I use the following method to apply a constant force to my SCNnode in the scene,
func applyForceToDrone(powerApply: Double, isHovering: Bool, gravity : SCNVector3) {
let nodo = arrayDrone[0] // load the first drone in the scene
guard let lhBlade = nodo.childNode(withName: "Rotor_L_2", recursively: true) else {fatalError()}
guard let rhBlade = nodo.childNode(withName: "Rotor_R_2", recursively: true) else {fatalError()}
if isHovering == true {
print("x gravity = \(gravity.x), \(gravity.y) \(gravity.z)")
let force = SCNVector3(gravity.x, abs(gravity.y), gravity.z)
nodo.physicsBody?.applyForce(force, asImpulse: false)
} else {
print("apply power \(powerApply)")
let positionBladeLH = lhBlade.position
let positionBladeRH = rhBlade.position
let force = SCNVector3(0, powerApply, 0)
nodo.physicsBody?.applyForce(force, at: positionBladeLH, asImpulse: false)
nodo.physicsBody?.applyForce(force, at: positionBladeRH, asImpulse: false)
let alt = nodo.position.y // position is wrong ... is always the starting position
print(alt)
}
}
I use than this func in the render method to fly my drone.
func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) {}
i want to read the current position of the node every time the force is applied.
How can I get the update position while the render is applying the force.
I tried with :
let alt = nodo.position.y
but it always gave me the starting position of the node and not the one after the force is applied.
Thanks