I have 3 NPC's that each have their own circular physicsBody meant to mimic bouncy balls in zero gravity - more precisely, bouncy balls that never stop moving due to restitution = 1.0; (bounciness 100%) friction = 0.0; (No friction) linearDampening = 0.0; (Collisions don't impact the NPC). If either of these NPC's collide/contact with another one, then their velocity increases. They start moving so fast that it begins to force the levels boundaries/physicsBodies (which are supposedly non-dynamic) actually shift/move from the impact. Below are the if statements I wrote in the update method to keep these 3 NPC's physicsBody.velocities under control. Could someone take a look and tell me if there's a better way of doing this? I basically want to have limited maximum velocities/moving speeds for all 3 NPC's at all times that they can't exceed.
-(void)update:(CFTimeInterval)currentTime
{
/* Called before each frame is rendered */
//Track ball velocities.
if (_npcRed.physicsBody.velocity.dx > 1000 || _npcRed.physicsBody.velocity.dy > 1000)
{
NSLog(@"RED's moving too fast; lowering velocity");
_npcRed.physicsBody.velocity = CGVectorMake(500, 500);
}
else
{
NSLog(@"RED's at stable speed");
}
if (_npcBlue.physicsBody.velocity.dx > 1000 || _npcBlue.physicsBody.velocity.dy > 1000)
{
NSLog(@"BLUE's moving too fast; lowering velocity");
_npcBlue.physicsBody.velocity = CGVectorMake(500, 500);
}
else
{
NSLog(@"BLUE's at stable speed");
}
if (_npcGreen.physicsBody.velocity.dx > 1000 || _npcGreen.physicsBody.velocity.dy > 1000)
{
NSLog(@"GREEN's moving too fast; lowering velocity");
_npcGreen.physicsBody.velocity = CGVectorMake(500, 500);
}
else
{
NSLog(@"GREEN's at stable speed");
}
}