Problem = I have a locomotive trying to follow an oval-shaped UIBezierPath
. The challenge is that when I use orientToPath:true
in my call to SKAction.follow
, the locomotive immediately rotates even though the locomotive is initially positioned on the straight portion of the oval before it reaches the rounded portion of the oval.
If I could prevent this initial rotation, then the rotation would not happen until it reached the rounded portion of the oval - as it should.
So, can you please provide some guidance as to how I could prevent this initial rotation?
Here is the code:
func createTrainPath() {
// this custom method ensures that the locomotive
// moves CW, versus CCW
trackPath = getBezierPath(theNode: myTrain, offset: 0.0)
} // createTrainPath
func startFollowTrainPath() {
let theSpeed = Double(5*thisSpeed)
var trainAction = SKAction.follow(
trackPath.cgPath,
asOffset: true,
orientToPath: true, // <==
speed: theSpeed)
trainAction = SKAction.repeatForever(trainAction)
myTrain.run(trainAction, withKey: runTrainKey)
} // startFollowTrainPath