I’m attempting to write a game for iOS in Swift using Scenekit. I’ve created a rocket, and when touching on the left side of the screen I apply the following force:
let force = SCNVector3(0, 1.2, 0)
let pos = SCNVector(-0.1, 0, 0)
Rocket.physicsBody?.applyForce(force, at: pos, asImpulse: false)
…and when touching the right side of the screen I apply the following force:
let force = SCNVector3(0, 1.2, 0)
let pos = SCNVector(0.1, 0, 0)
Rocket.physicsBody?.applyForce(force, at: pos, asImpulse: false)
This almost has the effect I want, as my rocket begins to fly, tilts left and right, however it is always going up on the Y axis (by the 1.2), rather than in the direction it is facing.
How do I get it to go in the direction it is facing?
Thanks for the reply Mr Gerrard MBE, I didn’t realise you did coding since retiring from footy!
I forgot to mention my game was a physics based game, so using velocity to rotate would result in my rocket pointing down when gravity was in effect when I would like it to point in the direction of last thrust (a little like the game ‘Thrust’ from years ago)
I’ve also read that mixing actions (like rotateTo) with physics is not a good idea.
I’m currently experimenting with an empty node in front of my rocket, but am struggling to work out its vector in relation to the orientation of my rocket.