How to check bodies stopped moving after collision?

Official forum for the Chipmunk2D Physics Library.
Post Reply
guptanikesh
Posts: 8
Joined: Mon Aug 31, 2009 5:09 am
Contact:

How to check bodies stopped moving after collision?

Post by guptanikesh »

Hello I am new to chipmunk. Will somebody help me to find out "How to check bodies stopped moving after collision?"
Thanks
maximile
Posts: 157
Joined: Mon Aug 20, 2007 12:53 pm
Location: London, UK
Contact:

Re: How to check bodies stopped moving after collision?

Post 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.
guptanikesh
Posts: 8
Joined: Mon Aug 31, 2009 5:09 am
Contact:

Re: How to check bodies stopped moving after collision?

Post 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");
	}
User avatar
Tam Toucan
Posts: 141
Joined: Tue Jun 23, 2009 4:26 pm
Contact:

Re: How to check bodies stopped moving after collision?

Post 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.
guptanikesh
Posts: 8
Joined: Mon Aug 31, 2009 5:09 am
Contact:

Re: How to check bodies stopped moving after collision?

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 26 guests