Sunday, October 27, 2019

movement - Moving a ship forward from rotation


I am making a simple space simulator, where the player can control a ship using 2 controls, one for pitch and one for bank. The ship is properly rotated but I cannot figure out how to make the ship move forward based on that angle. Here's what the code looks like right now:


func renderer(renderer: SCNSceneRenderer, updateAtTime time: NSTimeInterval) {

let t=CGFloat(time - lastTime)


ship!.transform = CATransform3DRotate(CATransform3DRotate(CATransform3DRotate(ship!.transform, ud*t, -1, 0, 0), 0.00, 0, 1, 0), lr*t, 0, 0, 1);

ship!.position = ?

}

I tried every combination of vector, euler angles, matrices, quaternions that I could think of/read about with no success. I am probably missing something stupid but cannot find what it is.


The code is in Swift using Scenekit, but language doesn't matter that much to me and I can translate any algorithm. It's also worth noting it does not work like Unity and Quarternions/Vectors don't have properties like .forward() etc.


Thank you for your help!





No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...