|
Hey, Im trying to get my rigidbody to stop its code when it is falling, so i tried an if rigidbody.velocity.y is != to 0, this did work in checking if the player is falling or not, but then my other code could kick in. In the code it used rigidbody velocity to move left and right, NOT up and down, but this still trips the if velocity.y statement. how do I get around this?
(comments are locked)
|
|
I dont know how I this works but I moved my 'check the rigidbody y velocity' if statement to a late update and it works fine! maybe because it is called after the move velocity? :) LateUpdate() is called neither before nor after physics simulation. LateUpdate() happens after Update() within the course of a single frame. Physics simulation, on the other hand, occurs after every interval of Time.fixedDeltaTime.
Jun 25 '11 at 05:01 AM
Dreamblur
(comments are locked)
|

I'm not sure if I follow your question, but it sounds like you might need to use a threshold value and a < comparison, e.g. 'if (velocity.y < fall_threshold)', where 'fall_threshold' is a negative value. This way, slight variations in the y velocity (e.g. due to numerical error) won't be registered as 'falling'.
Thats what I know how to do, the real problem is the velocity.y is influenced by moving the rigid-body on the x axis?
I would say that the friction on the rigidbody causes some slight changes on the y axis of it's velocity. If this means you are getting small fragments in there, you will indeed need to check for something like Jesse said, as the falling velocity will be a negative value.