Shift72
Shift72

Reputation: 448

Swift 2: SKAction to change y position

I have a SKAction that changes the y position of a sprite. The sprite is affected by gravity towards the right, and when i set the x position in the SKAction to the sprite's position the sprite movement is slowing down while the Action is running.

How can i change this so that the x movement is not effected by the action running?

let moveDown = SKAction.moveTo(CGPoint(x: player.position.x, y: 0), duration: 0.3)
    player.runAction(moveDown)

Upvotes: 1

Views: 338

Answers (2)

Shift72
Shift72

Reputation: 448

Solved it using this code:

   let moveDown = SKAction.moveToY(0, duration: 0.3)
    player.runAction(moveDown)

Upvotes: 1

mccoyLBI
mccoyLBI

Reputation: 171

You could try using linearDamping. I'm not sure this is exactly what you're looking for, but it's a property that reduces the body’s linear velocity.

player.physicsBody!.linearDamping  = 0.0

Let me know if this works for you or if this wasn't what you were looking for!

Upvotes: 1

Related Questions