- Home /
Gravity doesn't work
Hello,
I think this line in my script makes the velocity of the rigidbody on the y axis zero, so the gravity doesn't work. How can I fix this?
rigidbody.velocity = transform.forward * Input.GetAxis("Vertical") * speed * Time.deltaTime;
Comment
Answer by Koharu · May 11, 2014 at 06:07 PM
As far as I know, transform.forward is Vector3(0,0,1). So, all your math affects only z axes.
Answer by Hachley · May 11, 2014 at 06:21 PM
Yeah, remember the X Y Z sequence, so the (0,0,1) means 0x 0y 1z. If you'd like the code to affect the Y only, then try something like:
rigidbody.velocity = transform.up * Input.GetAxis("Vertical") * speed * Time.deltaTime;
Or if you want it to affect both Y and Z, then:
var there : Vector3(1,0,1);
rigidbody.velocity = transform.there * Input.GetAxis("Vertical") * speed * Time.deltaTime;
It doesn't work. It says "there is not a memeber of transform"