Search Unity

Question My character can move with WASD, but it slides and shows no animations

Discussion in 'Scripting' started by lucutes, Jun 8, 2020.

  1. lucutes

    lucutes

    Joined:
    May 27, 2020
    Posts:
    12
    My code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Movement : MonoBehaviour
    6. {
    7.     private Animator _animator;
    8.  
    9.     public float MaxSpeed = 10;
    10.     // Start is called before the first frame update
    11.     void Start()
    12.     {
    13.         _animator = GetComponent<Animator>();
    14.     }
    15.  
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    19.         if (_animator == null) return;
    20.  
    21.         var x = Input.GetAxis("Horizontal");
    22.         var y = Input.GetAxis("Vertical");
    23.  
    24.         Move(x, y);
    25.  
    26.     }
    27.  
    28.     private void Move(float x, float y)
    29.     {
    30.         _animator.SetFloat("VelX", x);
    31.         _animator.SetFloat("VelY", y);
    32.  
    33.         transform.position += (Vector3.forward * MaxSpeed) * y * Time.deltaTime;
    34.         transform.position += (Vector3.right * MaxSpeed) * x * Time.deltaTime;
    35.     }
    36. }
    37.  
    What console says when running:


    They don't look like errors, so they don't really mean anything?
     
    Last edited: Jun 8, 2020
  2. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
    Are you sure your string names for the animator are correct?
     
  3. lucutes

    lucutes

    Joined:
    May 27, 2020
    Posts:
    12
    What do you mean exactly? I didn't have any errors while compiling.
     
  4. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
    You won't until it tries to run it, even then you will get a warning. Are you sure the animator contains floats for "VelX" and "VelY"?
     
  5. lucutes

    lucutes

    Joined:
    May 27, 2020
    Posts:
    12


    Basically yes, well at least I think soo, I uploaded the picture just in case if I determined it right.
     
  6. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    That screen looks right. Is it possible your animator isn't getting into that blend tree? If you go up one level on the animator, is the blend tree the first thing your animator goes to?
     
  7. lucutes

    lucutes

    Joined:
    May 27, 2020
    Posts:
    12
    My option to "Move up" is greyed out
     
  8. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    ?

    Click on "Base Layer" top of the animator graph window
     
  9. lucutes

    lucutes

    Joined:
    May 27, 2020
    Posts:
    12
    "Go up one level" what does that mean? Anyways I upload pic of the base layer of the animator.
     
  10. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    That's what I was asking. OK, that is set up correctly.

    Going back to your earlier screenshots, I just saw that your console window shows 999+ warnings and errors. What are those? (scroll past the first page)