Advertisement
Cookie042

Fixed up

Feb 14th, 2014
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class accel : MonoBehaviour
  5. {
  6.    
  7.     public float maxVel = 10;
  8.     public float accelRate = 900f;
  9.     // Update is called once per frame
  10.     void FixedUpdate ()
  11.     {      
  12.         Debug.Log ("before accel: " + rigidbody.velocity.magnitude);
  13.         rigidbody.AddForce(transform.forward*accelRate, ForceMode.Acceleration);    
  14.         //fix: rigidbody.velocity = rigidbody.velocity + (transform.forward*accelRate) * Time.deltaTime;
  15.         Debug.Log ("after accel: " + rigidbody.velocity.magnitude);
  16.        
  17.         if (rigidbody.velocity.magnitude > maxVel)
  18.         {
  19.             rigidbody.velocity = rigidbody.velocity.normalized*maxVel;
  20.             Debug.Log ("after cap: " + rigidbody.velocity.magnitude);
  21.         }
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement