-1

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?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
srgnbcrk
  • 11
  • 2

3 Answers3

0

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

Knight0fDragon
  • 16,609
  • 2
  • 23
  • 44
0

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.

Steve Ives
  • 7,894
  • 3
  • 24
  • 55
-1

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.

Maci
  • 123
  • 8