Hey,
in my game I want to have moveable platform that move from A to B and back again (endless). So I read the start and end position from an XML and the body pointers are stored in an array (start and end position are also stores in an array). So in init the bodies are created as kinematic and get the velocity by setLinearvelocity (which direction is calculated with start and end position). In my update I iterate over the body pointers of the platforms and look if the get out of the boundaries . If so I just reverse the velocity. here's one condition I check for platforms that start with moving from the left to the right:
else if (xDestination > xSource && ySource == yDestination) {
if ((currentPosition.x*PTM_RATIO > xDestination) ||
currentPosition.x*PTM_RATIO < xSource) {
body->SetLinearVelocity(-body->GetLinearVelocity());
}
}
It works fine in the beginning but after I've played some time the bodies hang at the boundaries (I think they reverse the velocity all the time) and sometimes they get back in line.
I thought my approach was pretty straight forward but somehow it doesn't work properly. Any Ideas what that might be?
I should mention that my positions in the XML are something like x=0.28381 and when I set the position I do it by (x*screenSize.width,y*screenSize.height) so that it's positioned equally on every device.
ANY HELP SO MUCH APPRECIATED!
in my game I want to have moveable platform that move from A to B and back again (endless). So I read the start and end position from an XML and the body pointers are stored in an array (start and end position are also stores in an array). So in init the bodies are created as kinematic and get the velocity by setLinearvelocity (which direction is calculated with start and end position). In my update I iterate over the body pointers of the platforms and look if the get out of the boundaries . If so I just reverse the velocity. here's one condition I check for platforms that start with moving from the left to the right:
else if (xDestination > xSource && ySource == yDestination) {
if ((currentPosition.x*PTM_RATIO > xDestination) ||
currentPosition.x*PTM_RATIO < xSource) {
body->SetLinearVelocity(-body->GetLinearVelocity());
}
}
It works fine in the beginning but after I've played some time the bodies hang at the boundaries (I think they reverse the velocity all the time) and sometimes they get back in line.
I thought my approach was pretty straight forward but somehow it doesn't work properly. Any Ideas what that might be?
I should mention that my positions in the XML are something like x=0.28381 and when I set the position I do it by (x*screenSize.width,y*screenSize.height) so that it's positioned equally on every device.
ANY HELP SO MUCH APPRECIATED!