I've noticed something very odd with my subclassed SKSpriteNode
with physicsBody attached and responding to impulses.
It has a SKPhysicsBody
attached, but when applying impulses to the sprite it vibrates during movement. It's highly annoying and looks awful.
What could be causing this?
Here's the setup code:
self.texture = [[SKTextureAtlas atlasNamed:@"karl"]textureNamed:@"karlidle-1"];
self.size = CGSizeMake(69.0, 93.0);
self.userInteractionEnabled = NO;
self.name = @"karl";
self.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(69.0, 93.0)];
self.physicsBody.dynamic = YES;
self.physicsBody.allowsRotation = NO;
self.physicsBody.affectedByGravity = YES;
self.physicsBody.usesPreciseCollisionDetection = YES;
self.physicsBody.mass = 1.0;
self.physicsBody.linearDamping = 0.0;
self.physicsBody.angularDamping = 0.0;
self.physicsBody.restitution = 0.3;
self.physicsBody.categoryBitMask = karlCategory;
self.physicsBody.collisionBitMask = obstaclesCategory|floorCategory|wallCategory;
self.physicsBody.contactTestBitMask = obstaclesCategory|floorCategory|wallCategory;
and applying the impulse:
if (self.physicsBody.velocity.dy >= kKarlMaxVelocity) {
self.physicsBody.velocity = CGVectorMake(0, kKarlMaxVelocity);
}
else if (self.physicsBody.velocity.dy <= kKarlLowVelocityBoostThreshold){
self.physicsBody.velocity = CGVectorMake(0, kKarlVelocityImpulseIncrement*kKarlVelocityBoost);
}
else{
[self.physicsBody applyImpulse:CGVectorMake(0, kKarlVelocityImpulseIncrement)];
//[self.physicsBody applyForce:CGVectorMake(0, 3000) atPoint:self.frame.origin];
//self.physicsBody.velocity = CGVectorMake([self returnNormalisedXVelocity], self.physicsBody.velocity.dy);
}
One thing to note is I clamp the velocity so it doesn't go nuts, but turning this off doesn't seem to fix the issue.