Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1.     void FixedUpdate()
  2.     {
  3.         Vector2 input = new Vector2 (Input.GetAxis ("Horizontal"), Input.GetAxis ("Vertical"));
  4.         rigidbody2D.AddForce (input * speed);
  5.  
  6.         if (rigidbody2D.velocity != Vector2.zero) {
  7.             var a = rigidbody2D.rotation / 360.0f * 2.0f * Mathf.PI;
  8.        
  9.             var v = rigidbody2D.velocity.normalized;
  10.             var orientation = new Vector2(-Mathf.Sin (a), Mathf.Cos (a));
  11.  
  12.             var angleDiff = Vector2.Angle (v, orientation);
  13.             angleDiff = Mathf.Min(20.0f, angleDiff);
  14.             var cross = Vector3.Cross (v, orientation);
  15.  
  16.             if (cross.z > 0) {
  17.                 angleDiff = -angleDiff;
  18.             }
  19.  
  20.             var torque =
  21.                 (angleDiff * turnSpeed); // / (1.0f + Mathf.Abs(rigidbody2D.angularVelocity));
  22.  
  23.             rigidbody2D.AddTorque(torque);
  24.         }
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement