[Phizix] Test if a body is not moving
Hello,
I have a few bodies moving and I want to test if a body stops moving. How would you do it ?
I think of making a fastloop, select each (body from ID 0 to "number of bodies") and to test the Xvelocity and Yvelocity of each body. But I just need to test a special kind of bodies, not all of them.
Would somebody have a smater suggestion ?
Thanks in advance
Re: [Phizix] Test if a body is not moving
A fast loop? Just use the condition compare 2 general values.
Re: [Phizix] Test if a body is not moving
I think it's impossible, Dynamite, because you have to give the ID of the body you want to test. You can't write as a condition "XVelocity=0", you must write "XVelocity (IDbody)=0".
Thanks anyway...
Re: [Phizix] Test if a body is not moving
I can't come up with a better suggestion. You'll have to loop through them, but if you're both adding and removing bodies in your game, the body ID's might not be ranging from 0-9 just because the body count is 10. By that reason, you might usually want to loop through the objects that is used to graphically display the physical bodies, and get the physical ID's from them.
Re: [Phizix] Test if a body is not moving
Thanks, I didn't think of the adding and removing bodies problem : it's sure I'll loose the amount of the IDs. Your suggestion is good (but it appears to be more difficult than I thought :eek: )...
Re: [Phizix] Test if a body is not moving
When a body is created, attach an active to it and set one of it's values to the last created body id.
Then you can loop through the actives, and check the speeds of each body.
Re: [Phizix] Test if a body is not moving
Yes, Daniel, I think that's the best way to do it. Thank you.
Re: [Phizix] Test if a body is not moving
Well, I don't know what I miss but it seems difficult to get a XVelocity and a YVelocity equal to 0. They always seem to be 3 or more... But I must check again...
Re: [Phizix] Test if a body is not moving
They are rarely 0, but check em like this... Set a limit to where the object is considered still enough... Then when both x and y velocity are below the limit add 1 to another value... (reset it if one the velocities goes above that limit).. Then if that value goes above, say 50 (approx 1 sec of non movement).. trigger your action :)
Re: [Phizix] Test if a body is not moving
Thank you, Daniel, I'll do as you said.