Page 1 of 1
How to check bodies stopped moving after collision?
Posted: Sat Sep 12, 2009 10:49 am
by guptanikesh
Hello I am new to chipmunk. Will somebody help me to find out "How to check bodies stopped moving after collision?"
Thanks
Re: How to check bodies stopped moving after collision?
Posted: Sat Sep 12, 2009 11:29 am
by maximile
Check the body's velocity. If it's under a certain value, you can say it has stopped moving. Perhaps make sure it stays under that value for a few frames first, depending on why you want to know.
Re: How to check bodies stopped moving after collision?
Posted: Mon Sep 14, 2009 3:19 am
by guptanikesh
Thanks maxi.. I had already tried your suggestion before posting it here but it was not working.
I was trying some thing like this but it never happened
Code: Select all
if(([self ball].body->v.x == 0.00 || [self ball].body->v.x == -0.00) && ([self ball].body->v.y == 0.00 || [self ball].body->v.y == -0.00))
{
NSLog(@"ball is stopped");
}
Re: How to check bodies stopped moving after collision?
Posted: Mon Sep 14, 2009 5:06 am
by Tam Toucan
This might not be the problem, but you can't really compare floats to exact numbers like that.
Do a search for "comparing floats c" (or c++) and you'll find some information. Basically you need to check it is within a small range.
In C++ there is std::numeric_limits<float>::epsilon(), Objective C may have a similar value, or you can just use a very small value.
Re: How to check bodies stopped moving after collision?
Posted: Mon Sep 28, 2009 3:32 pm
by guptanikesh
Thanks Tam
Apologies for delayed reply.
I couldn't find anything like that which you mentioned. But I wrote something my own after reading more about comparing floats using epsilon.
Thanks once again
Regards
Nikesh