Search Unity

Character not turning properly. (first unity project)

Discussion in 'Scripting' started by thingyat1, Jan 26, 2018.

  1. thingyat1

    thingyat1

    Joined:
    Jan 26, 2018
    Posts:
    2
    I just started using unity and I figured I'd start by making a character.

    My character wont turn left or right when "Apply root motion" is disabled how ever it will when I enable it but then the animation stops. I think it's a problem with the script but as I said I just started so I'm not sure whats wrong.

    With root motion enabled:


    With root motion disabled:


    My script:https://imgur.com/a/yWlRm


    Any help would be appreciated :)


    Ps I got the script from this tutorial:
     
  2. BubyMB

    BubyMB

    Joined:
    Jun 6, 2016
    Posts:
    140
    use transform.eulerAngles instead
     
  3. thingyat1

    thingyat1

    Joined:
    Jan 26, 2018
    Posts:
    2
    I messed around with the script a bit but still the same problem :/

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Anim : MonoBehaviour {
    6.  
    7.     public Animator playerAnim;
    8.  
    9.     // Use this for initialization
    10.     void Start ()
    11.     {
    12.         playerAnim = GetComponent<Animator>();
    13.     }
    14.    
    15.     // Update is called once per frame
    16.     void Update ()
    17.     {
    18.         float walkInput = Input.GetAxis("Horizontal");
    19.  
    20.         if (walkInput > 0f)
    21.         {
    22.             playerAnim.SetBool("Walking",true);
    23.             transform.eulerAngles = new Vector3(0,-90,0);
    24.         }
    25.         else if (walkInput < 0f)
    26.         {
    27.             playerAnim.SetBool("Walking",true);
    28.             transform.eulerAngles = new Vector3(0,90,0);
    29.         }
    30.         else
    31.         {
    32.             playerAnim.SetBool("Walking",false);
    33.             transform.eulerAngles = new Vector3(0,0,0);
    34.         }
    35.  
    36.  
    37.     }
    38. }
    39.  
     
    Last edited: Jan 26, 2018
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    It's much easier to start making a psuedo character by just using movement, and not including animation.
    Then you can get a feel for how it's working and later add the animation. :) At least, in my opinion.

    For future reference, have a look at this page: https://forum.unity3d.com/threads/using-code-tags-properly.143875/
    It will show you how you can post your scripts/code on the forums in a nicely formatted fashion.

    Welcome to Unity :)