Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to make animations for Game Object that follows a spline (Bézier Path Creator)

Discussion in 'Animation' started by Peilo77, Jan 1, 2021.

  1. Peilo77

    Peilo77

    Joined:
    Aug 18, 2020
    Posts:
    18
    Hi there,

    I have posted this thread also in 2D and just now discovered the Animation section.

    I have downloaded the asset Bézier Path Creator by Sebastian Lague and want to use it for a 2D game object, an enemy (npc) Spaceship, so that game Object follows the set Path and while moving up and down makes up and down tilting movement animations (the spaceship tilts up and down).

    Please note I'm a beginner and any help is appreciated :)

    I have made a script for my Player spaceship that makes Tilt animations when moving Up or Down and want to do the same for the NPC Spaceships (it's a side scrolling shoot'em up game). The Player flies from left to right and is turned to the right and the NPCs come from the left and are facing left.

    I used the Animator to animate this and have two different Tilt animations when moving up and two different Tilt animations when moving down (depending on how long you move up or down the according animation is displayed). Also there is an animation for the Shooting in every possible position. Please look below:



    For the movement animation I used a Float Parameter "VerticalSpeed". For example for the Moving UP1 animation from the Idle Position the transition is "VerticalSpeed" is "Greater" than "0" (here this one example):



    All this works fine and all Animations play as they should for the Player.

    Now for the NPC Spaceship I want to do exactly the same but the whole System is of course different since I can't do this via the "Input.GetAxis" System as for the player and below are the lines of code I did to make the animations work for the Player:

    float m_VerticalMovement;

    void Awake()
    {
    anim = GetComponent<Animator>();
    }

    void Update()
    {
    AnimateConditions();
    }

    void AnimateConditions()
    {
    m_VerticalMovement = Input.GetAxis("Vertical");

    anim.SetFloat("VerticalSpeed", m_VerticalMovement);
    }


    For the NPC Spacehip, as I'm a bloody beginner, I used the Bézier Path for the movement direction and the NPC spaceship follows the Path perfectly fine but of course without the Tilt animations that I want similar to the Player animations.

    Below you can see the NPC spacehip and the Bézier Path it follows and when moving down I want it to do the Tilt down Animation and hen moving up I want it to do the Tilt up animation just like the Player.



    Here is the Code for the NPC Spaceship following the Bézier Path:



    Now how can I apply the same Tilt Animations for the Player to the NPC while it's moving up and down along the Bézier Path?

    Please note again I'm a bloody beginner and just started a few months ago as a hobby and really would appreciate if you could tell me how to proceed respectively where to put in the code lines.

    Many many thanks in advance for the help :)