1

I have an SCNNode that I would like to follow a path made up of points represented by SCNVector3s. However, rather than simply moving from point to point, I would like it to rotate to face in the direction of each point it moves towards. I know that setting a SCNLookAtConstraint could help with this, but I believe that this will only control the direction that the negative z axis faces, but I would like to be able to also control the y axis to ensure that its negative y axis always faces towards the track. I hope I was clear enough, but feel free to ask for clarification. Thanks!

  • You might be interested in the `updatePositionAndOrientationOf ` function from [this answer](https://stackoverflow.com/a/57359650/14351818) – aheze Apr 14 '21 at 01:30
  • 1
    Please correct me if I am wrong but I my understanding is that this function would be used to move an object into a position in front of my moving node, but I need my moving node to change it's orientation as it moves to face a specific point – Ben Proothi Apr 14 '21 at 01:41
  • Ah yeah. Nvm, it's not very relevant actually – aheze Apr 14 '21 at 01:42
  • you might use some SCNConstraints – ZAY Apr 14 '21 at 16:20

1 Answers1

0

First the moveTo() - sounds like you have the right idea, just reset your next move in a completion handler. I'm assuming your doing this manually, so then set lookAt constraint when the next move starts and point it at the target. I "think" this will do what you want it to do, but depending on several things, like how fast this moves, are you flying through the targetNode or above it, certain situations could cause it to 'bounce'. If I'm understanding your y axis question correctly - lookAt is going to face the node and be locked on to it. If you are on a flat surface, I don't think it will be a problem.

func moveTo()
    {
        let vPanelName = moves[moveCount]
        let vLaneNode = grid.gridPanels[vPanelName]!.laneNodes[lane]
        let vAction = SCNAction.move(to: vLaneNode.presentation.position, duration: TimeInterval(data.getAttackSpeed(vGameType: gameType)))
        
        node.runAction(vAction, completionHandler:
            {
                self.moveCount += 1
                if(self.moveCount >= self.moves.count - 1)
                {
                    self.killMe(vRealKill: false)
                    return
                }
                else
                {
                    self.moveTo()
                }
        })
    }
Voltan
  • 1,170
  • 1
  • 7
  • 16