Search Unity

[C#] What/How would you do the movement Animations here? (progamming)

Discussion in 'Scripting' started by Trickzbunny, May 20, 2017.

  1. Trickzbunny

    Trickzbunny

    Joined:
    Jun 26, 2015
    Posts:
    64
    Hey!

    Usually I've made movement pretty simple:
    I'd have: W = forward/up, S = back/down and then A & D would be left/right strafe. etc.

    However, I am getting confused how I should code this here, since the Player looks at the mouse (raycast). Meaning Pressing W could be any of the animations (walkFront, walkBack, strafeLeft or right) because it would depend on the rotation of the Player aswell.

    Best watch video for an overview.
    I'm not an expert, explaining it in some depth would be much appreciated.

    Keep in mind the Camera never rotates.





    I have thought of 2 ways I think might work, but not sure how to execute it:

    I could base it of the Players movement from his movement on his transform and his current rotation:
    So,
    If player Transforms positive on X and his Rotation on Y is between 160 to 200, then he is walking backwards (since his movement is going up, but he is looking down)
    If player Transforms negative on X and his Rotation on Y is between 160 to 200, then he is walking front (since his movement is going down, but he is looking down)

    If player Transforms positive on X and his Rotation on Y is between -20 to 20, then he is walking fron t(since his movement is going up, and he is looking up)
    If player Transforms negative on X and his Rotation on Y is between -20 to 20, then he is walking backwards (since his movement is going down, but he is looking up, meaning he is walking backwards)

    Then continue this with every single aspect.. which would basically be a on of lines just changed slightly for the different angles.


    Or base it of the Mouse Location and what key is pressed:
    If GetKey W:
    and mouse is on the top, then walkFront, (with that i mean if the mouse is in an area on top of the player/top of the screen)
    If mouse is on the bottom, then walkBack,
    If mouse is on the left, then strafe right,
    If mouse is on the right, then strafe left.

    Then basically the same thing for ASD but change whatever animation it would play depending on the mouse position.

    What are your thoughts?


    Thank you :)
     
    Last edited: May 20, 2017
  2. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
    You guess could trigger the animations based on a float values for horizontal and forward/back velocity.
     
  3. Trickzbunny

    Trickzbunny

    Joined:
    Jun 26, 2015
    Posts:
    64
    Hey, I have updated the post above with 2 ways i think might work. Can you elaborate what you mean btw?