Hi all,
Forgive me if this sounds like a n00b question. I"m one.
I'm working on a billiards-like game. Player take turns in moving.
I need to know when the balls have stopped colliding and moving. Is there a callback function for this?
One workaround I'm thinking is to just assume that things have stopped one second after the last collision. The game world is small enough that this assumption is practically valid all the time. But I'm hoping there's a cleaner, built-in way.
Thanks in advance.
How to detect when all bodies have stopped moving
-
- Posts: 2
- Joined: Wed Jan 13, 2010 11:01 am
- Contact:
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: How to detect when all bodies have stopped moving
There isn't really a built in way no. One simple way to do it is to simply loop over all the balls and add the magnitude of their velocities together. When it falls below a certain amount, call it good enough.
Code: Select all
cpFloat vsum = 0.0f;
for(ball in balls){
vsum += cpvlength(ball->body->v);
}
if(vsum < 0.1f){
nextPlayerTurn = TRUE;
}
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 2
- Joined: Wed Jan 13, 2010 11:01 am
- Contact:
Re: How to detect when all bodies have stopped moving
That worked, and it's elegant, too.
Thanks!
Thanks!
Who is online
Users browsing this forum: Heise IT-Markt [Crawler] and 8 guests