I am trying to keep my SKSpriteNodes moving at a constant speed forever, even after collisions. I have set gravity to 0, friction to 0, and linear and angular dampening to zero, but the Sprites still slowly slow down to zero velocity. How can I keep them moving?
Based on the answer below, this is what I have tried: EDIT This code below works! I just had to check if the nodes were going slower than the limit and speed them up.
[self enumerateChildNodesWithName:kBallName usingBlock:^(SKNode *node, BOOL *stop)
{
SKSpriteNode *ball = (SKSpriteNode *)node;
if (ball.physicsBody.velocity.dx < 0) {
if (ball.physicsBody.velocity.dx > -50)
ball.physicsBody.velocity = CGVectorMake(-50, ball.physicsBody.velocity.dy);
}
if (ball.physicsBody.velocity.dx > 0) {
if (ball.physicsBody.velocity.dx < 50)
ball.physicsBody.velocity = CGVectorMake(50, ball.physicsBody.velocity.dy);
}
if (ball.physicsBody.velocity.dy < 0) {
if (ball.physicsBody.velocity.dy > -50)
ball.physicsBody.velocity = CGVectorMake(ball.physicsBody.velocity.dx, -50);
}
if (ball.physicsBody.velocity.dy > 0) {
if (ball.physicsBody.velocity.dy > 50)
ball.physicsBody.velocity = CGVectorMake(ball.physicsBody.velocity.dx, 50);
}
}];
Aucun commentaire:
Enregistrer un commentaire