Home > Blockchain >  Transition FPS Camera Animation from Idle to Walking?
Transition FPS Camera Animation from Idle to Walking?

Time:04-12

So, I recently learned how to animate certain objects, but I don't know how the code works.

I learned the animator tab, where idle camera animation will transition from walking if I am holding my movement keys. I searched tutorials on youtube and google, but all I can find are animations found on models, not actually on the camera.

If I used that logic on a camera, nothing actually happens, and I don't know what to write.

I've set a bool, which is labeled "WalkingForward", because I have different animations on different movements.

When it is true, the forward walk animation will play, and if false, it turns back to idle animation.

The only thing I can't figure out is a code that will detect the "Horizontal" and "Vertical" movements to start playing the animation.

Here is the link of my animator controller tab https://imgur.com/a/euM9yFl , and I would really appreciate if someone has an idea.

CodePudding user response:

You can handle/detect movement in the Update() method for a GameObject, then get the Animator for the Camera and set the Animator parameters.

See Unit Animation Parameters Docs for more info, but the general idea is something like this:

// Update method attached to wherever you want to detect movement
void Update()
{
    // isMovingHorizontally and iMovingVertically are not defined here
    // They could either be based off the speed/momentum of the GameObject
    // Or the input from the player 
    var isMovingHorizontally = isMovingHorizontally();
    var isMovingVertically = isMovingVertically();
    
    animator.SetBool("MovingHorizontally", fire);
    animator.SetBool("MovingVertically", fire);
}
  • Related