Character always facing camera while in orbit

Hello all,

I’m pretty new to Playcanvas, but wanted to reach out to get a bit of guidance on how to go about creating a routine that constantly keeps an animated character facing the camera.

A few notes:

  • I have a rigged character with a few animations attached to him.
  • I would like to have one animation looping
  • The camera is setup to orbit around a center group of objects
  • I would like the walk_left.json or walk_right.json animations to only trigger as the camera rotates, thus keeping the character always moving to face the camera.
  • The goal is to make this feel as natural as possible, which is why the character is not a child of the camera, or anything like that. That would create a sort of sliding effect, which is not what I’m looking for.

Any thoughts on how to go about this?

Only have a rough idea on what you are trying to do. As you only have walking left and walking right animations, I would guess that you want to check if the camera is to the right or to the left of the character and walk in said direction.

Yes, I understand this was a bit ambiguous, and I apologize for that. I’m really getting the hang of this.

I need to put this in code and see what works and what breaks, but the logic seems to be something like:

  • Get a script listening to the camera’s Y axis
  • Define ranges. Example:
  if (cam.y > 0 && cam.y < 45){ 
     if(newQuadrant != currQuadrant){
          trigger -> turn-right-anim; 
          currQuadrant = newQuadrant;
     }
  }

My questions are:

  • If the model is in the middle of an animation, will the turn-right-anim inturrupt the current animation? will the current animation pick up where it was after the turn-right-anim completes or will it send it back to the beginning.
  • I read somewhere else that the model should be broken up (legs, torso+arms, and head), so it’s easier to have a looping leg animation and just trigger the turn-right-anim on the legs while the torso and head are doing their thing.

Not sure what the exact code is for my little wanna-be routine, but I’ll dive in to the docs and tutorials.

Any suggested tutorials that tackle any of this would be much appreciated.

You can blend between animations which is straightforward to do: https://developer.playcanvas.com/en/tutorials/animation-blending/

For the actual problem itself, it does just sound like you just need to know which side of the character the camera is. If you get the right vector of the character and dot it against the vector between the character and the camera, you will get a value of > 0 or < 0 and this will tell you which side the camera is on in relation to the character.