Hello I am new to chipmunk. Will somebody help me to find out "How to check bodies stopped moving after collision?"
Thanks
How to check bodies stopped moving after collision?
-
- Posts: 8
- Joined: Mon Aug 31, 2009 5:09 am
- Contact:
-
- Posts: 157
- Joined: Mon Aug 20, 2007 12:53 pm
- Location: London, UK
- Contact:
Re: How to check bodies stopped moving after collision?
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.
-
- Posts: 8
- Joined: Mon Aug 31, 2009 5:09 am
- Contact:
Re: How to check bodies stopped moving after collision?
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
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");
}
- Tam Toucan
- Posts: 141
- Joined: Tue Jun 23, 2009 4:26 pm
- Contact:
Re: How to check bodies stopped moving after collision?
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.
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.
-
- Posts: 8
- Joined: Mon Aug 31, 2009 5:09 am
- Contact:
Re: How to check bodies stopped moving after collision?
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
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
Who is online
Users browsing this forum: No registered users and 26 guests