I have a rigidbody cube sat on a plane. I have some code to add upward force to the cube when I press space bar. I’m attempting to clock it’s velocity when it collides with the plane on it’s way back down, so that I can get a sense for falling velocities depending on how high up I send the cube. This is the code I’m using:
void OnCollisionEnter(Collision col){
Debug.Log ("Collision at " + gameObject.rigidbody.velocity);
}
The problem is that it doesn’t actually log every time the cube lands. Only about 1 in 3 times actually show up in the console. Any idea why?
Here’s the code for controlling the cube:
void FixedUpdate () {
float h = Input.GetAxis("Horizontal") * torqueModifier * Time.deltaTime;
float v = Input.GetAxis("Vertical") * torqueModifier * Time.deltaTime;
gameObject.rigidbody.AddTorque(transform.forward * h);
gameObject.rigidbody.AddTorque(transform.right * v);
if (Input.GetKeyDown(KeyCode.Space))
{
gameObject.rigidbody.AddForce (transform.up * thrustModifier);
}
}