x


Check if rigidbody is falling

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?

more ▼

asked Jun 18 '11 at 11:13 AM

Jason Hamilton gravatar image

Jason Hamilton
445 68 73 80

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'.

Jun 18 '11 at 03:40 PM Jesse Anders

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?

Jun 19 '11 at 07:50 AM Jason Hamilton

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.

Jun 19 '11 at 08:16 AM RodrigoSeVeN
(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

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? :)

more ▼

answered Jun 25 '11 at 04:37 AM

Jason Hamilton gravatar image

Jason Hamilton
445 68 73 80

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)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1787
x318
x97
x38

asked: Jun 18 '11 at 11:13 AM

Seen: 1794 times

Last Updated: Jul 16 '11 at 09:33 PM