Quantcast
Channel: Questions in topic: "left"
Viewing all articles
Browse latest Browse all 135

Using Accelerometer to move and rotate a 3d cube from left to right

$
0
0
I have been working on making a simple dodge the falling cube game and I have my movement script working, the problem that I'm having is that I want my cube (Player) to rotate on its z axis in the direction that it moves when it moves (ex: phone tilts left - cube moves left and rotates left on z axis). I would also like to know if anyone knew of a way that I could make the tilt either more or less sensitive. using System.Collections; using System.Collections.Generic; using UnityEngine; public class Move : MonoBehaviour { Rigidbody rb; float dirX; public float moveSpeed = 20f; // Use this for initialization void Start () { rb = GetComponent (); } // Update is called once per frame void Update () { dirX = Input.acceleration.x * moveSpeed; transform.position = new Vector2 (Mathf.Clamp (transform.position.x, -7.5f, 7.5f), transform.position.y); } void FixedUpdate() { rb.velocity = new Vector2 (dirX, 0f); } } That's my code it does work in moving my cube and rotating it on the z axis, but I want it to be a lot more smooth with the rotation. An example of the kind of movement I need in case I'm bad at explaining things, a good example would be in [Falling Blocks][1]. Thanks in advance. [1]: https://play.google.com/store/apps/details?id=com.emeraldtrackgames.fallingblocks

Viewing all articles
Browse latest Browse all 135

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>