Quantcast
Channel: Answers for "2D Rotate Object With Clamp Gradually. (C#)"
Viewing all articles
Browse latest Browse all 4

Answer by Mark Gossage

$
0
0
I have written very similar code before for having my planes rotate side-side when the player moves. This should get you going. public class PlayerMove : MonoBehaviour { public float maxMove=0.1f; // speed of the movement of the object public float maxTurn=30; // max angle it turns up/down public float turnRate=10; // how quickly it turns up/down Rigidbody2D rb2d; // Use this for initialization void Start () { rb2d = GetComponent (); } // Update is called once per frame void Update () { float delta = Input.GetAxis ("Vertical"); rb2d.MovePosition (rb2d.position + Vector2.up * delta * maxMove * Time.deltaTime); // simply set the angle //rb2d.rotation = turnAngle * delta; // use Lerp to set the angle rb2d.rotation = Mathf.Lerp (rb2d.rotation, maxTurn * delta, turnRate*Time.deltaTime); // you could use SmoothStep/SmoothDamp as well } }

Viewing all articles
Browse latest Browse all 4

Trending Articles



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