Where enemies are moving from every side to the screen. Falling enemies were easy to make with gravity.
But how can I make an enemy moving along the x axis or from down the screen to the top?
Where enemies are moving from every side to the screen. Falling enemies were easy to make with gravity.
But how can I make an enemy moving along the x axis or from down the screen to the top?
You may not want gravity then, turn off affectedByGravity
on all of your enemy nodes, then use the SKAction SKAction.moveBy(x:y:duration:)
to have you enemies move in a certain direction
If you really want to move things through gravity, you could use Linear Gravity SKFieldNode https://developer.apple.com/documentation/spritekit/skfieldnode
By create a 'vertical' Linear Gravity field and a 'Horizontal' linear field node and the correct use of the fieldBitMask
, you could have some objects falling vertically as they are affected by the vertical gravity field and other objects 'falling' horizontally due to the horizontal gravity field.
You can use a SKAction for this:
let moveAction = SKAction.moveBy(x: 100, y: 100, duration: 2)
entity.run(moveAction)
This will move your node up and to the right.