TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: SKSpriteNode to follow "complex" path?

Forums > Swift


Hi, How to achieve movement of the sprite with complex lines?

For example:

let path = UIBezierPath()
path.move(to: CGPoint(x: -160, y: 544))
path.addLine(to: CGPoint(x: 160, y: 256))
path.addLine(to: CGPoint(x: 224, y: 96))
path.addLine(to: CGPoint(x: -160, y: 0))
path.addLine(to: CGPoint(x: -122, y: -33))
path.addLine(to: CGPoint(x: 188, y: -125))
path.addLine(to: CGPoint(x: 0, y: -400))
    .follow(path.cgPath, asOffset: true, orientToPath: true, speed: 10)

but this not work at all... I wonder does anyone have similar problem?



I forgot to set initial position of enemy sprite to .zero, so the movment and path is ok, but they far from visible scene... So, sprite set to .zero, then .follow.


@twostraws  Site AdminHWS+

You will have more chance of getting help if you can clarify what you mean by it not working. Are you saying nothing moves, or it moves but doesn't move as you expect? Or something else?



Oh, yes, somtimes I forgot the main part... :( (assmed that is obvius)

All enemy sprites not moves at all.


@twostraws  Site AdminHWS+

Some things to check:

  1. Do you have more than one enemy on screen, and it's being applied to the wrong one?
  2. Do you have physics acting on the enemy, stopping it from moving?
  3. Does your scene have a sensible size?



It was number 3. Enemies path was way off screen, and in the update is removed everything that is out of safe rect... Beginners mistake.


This actually helped me as well. Using the move for a differerent reason, but helped clarify a good bit. Thanks for posting and thanks for putting up the answer.


Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.