Hello, I have a problem, I have no idea how to move an object relative to its rotation. I rotate an object using "SCNAction.rotateBy" and move it "SCNAction.move". I need to make it so that after rotation at a certain angle, the object moves in a given direction of rotation. Example: We have a spacecraft in 3 dimensional dimensions, I turn it to a certain angle "a" (suppose 18 degrees), after which I press the button and it starts moving in the direction of this ship. I ask for your help.
var YRotate = CGFloat(0 * Double.pi)
func Rotate(){ // rotate ship
if stopRotate == true{
YRotate = CGFloat(2 * Double.pi)
}else{
YRotate = CGFloat(-2 * Double.pi)
}
let action = SCNAction.rotateBy(x: 0, y: YRotate, z: 0, duration: 10)
let repAction = SCNAction.repeatForever(action)
Swift.print(ShipSpaceNode.rotation)
ShipSpaceNode.runAction(repAction)
}
var x = 0
var xy = 0
func Click(){ // moving ship
if stop == true{
x = 1
xy = 1
} else{
x = 0
xy = -1
}
Swift.print(ShipSpaceNode.position)
let koord = SCNVector3(Float(xy), 0 , 0)
let moveUp = SCNAction.move(by: koord, duration: 5)
let hoverSequence = SCNAction.sequence([moveUp])
let loopSequence = SCNAction.repeatForever(hoverSequence)
ShipSpaceNode.runAction(loopSequence)
}