Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void FixedUpdate()
- {
- Vector2 input = new Vector2 (Input.GetAxis ("Horizontal"), Input.GetAxis ("Vertical"));
- rigidbody2D.AddForce (input * speed);
- if (rigidbody2D.velocity != Vector2.zero) {
- var a = rigidbody2D.rotation / 360.0f * 2.0f * Mathf.PI;
- var v = rigidbody2D.velocity.normalized;
- var orientation = new Vector2(-Mathf.Sin (a), Mathf.Cos (a));
- var angleDiff = Vector2.Angle (v, orientation);
- angleDiff = Mathf.Min(20.0f, angleDiff);
- var cross = Vector3.Cross (v, orientation);
- if (cross.z > 0) {
- angleDiff = -angleDiff;
- }
- var torque =
- (angleDiff * turnSpeed); // / (1.0f + Mathf.Abs(rigidbody2D.angularVelocity));
- rigidbody2D.AddTorque(torque);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement