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

Blendtree with mouse input

Discussion in 'Animation' started by kotoffei, May 19, 2021.

  1. kotoffei

    kotoffei

    Joined:
    Jul 8, 2019
    Posts:
    15
    Hello everyone!

    I'm not sure that i am in right place, because it is about animation and navmesh...

    I would like to implement a left and right movement for my character on mouse click, but make him looing forward while moving.

    I have a blend tree with 5 states (idle, moving forward, backward, left and right).

    But i struggle a little bit with code, don't really get how to implement the values. So i guess i have to to implement negative and positive values for each axe... Shall i do it with if statement, for exemple if the mouse is on left of the screen :

    Code (CSharp):
    1. if (Input.mousePosition.y >= Screen.height / 2)
    2.             {
    3.                 animator.SetFloat("forwardSpeed", 5);
    4.             }
    And i also some issues with player view. Shall i just set angular speed to 0, or is there some better ways?

    Is there some good practice for this problem?



    Thank you in advance.
     
  2. kotoffei

    kotoffei

    Joined:
    Jul 8, 2019
    Posts:
    15