Working on a scenekit application, I have 2 boxes that can fire shots to each other for points. This is the calculation of the position where shots need to be made for the first box :
shot1 = SCNNode()
shot1.geometry = SCNSphere(radius: 0.5)
shot1.physicsBody = SCNPhysicsBody.dynamic()
shot1.position = SCNVector3Make
(boxNode1.position.x,
boxNode1.position.y + 1,
boxNode1.position.z - 1)
scnScene.rootNode.addChildNode(shot1)
And for the second box :
shot2 = SCNNode()
shot2.geometry = SCNSphere(radius: 0.5)
shot2.physicsBody = SCNPhysicsBody.dynamic()
shot2.position = SCNVector3Make
(boxNode2.position.x,
boxNode2.position.y + 1,
boxNode2.position.z + 1)
scnScene.rootNode.addChileNode(shot2)
Every shot is made just in good position and is thrown to the other box with applying force on its physicsBody as impulse.
For touch implementation I used touchesBegan to search for touches, then if the touch have the hitResult, I fire shots as I described above.
The problem happens where : If the shot for example shot1 hit boxNode2, the boxNode2 is moved backward as I expect it and this time if I fire a shot with boxNode2, the starting position of shot2 IS NOT in NEW location of boxNode2 as I expect it, and is starting to fire right where it was at the beginning!
So how can I fire shots from new position of the boxNodes?
Just use presentation
:
let realPosition = yourNode.presentation.worldPosition
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With