Search Unity

John Lemon on play- nothing moves

Discussion in 'Animation' started by junctionboss, May 18, 2019.

  1. junctionboss

    junctionboss

    Joined:
    May 11, 2014
    Posts:
    249
    I too just finished tut, nicely done tho I knew a lot of it already but still some I did not, but after done with script in place. and I made sure my script matched and its perfect - JohnLemon just rotates in place,doesn't have forwards movement of any kind. No errors of any kind anywhere.

    Using very latest unity through hub.
    Btw while not a long time programmer, I grasp in its entirety everything that is going on so its not that. Here is the script as attacked at bottom, in Inspector for John Lemon ;

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. public class PlayerMovement : MonoBehaviour
    6. {
    7.     public float turnSpeed = 20f;
    8.     Vector3 m_Movement;
    9.     Quaternion m_Rotation = Quaternion.identity;
    10.     Animator m_Animator;
    11.     Rigidbody m_Rigidbody;
    12.  
    13.     void Start()
    14.     {
    15.         m_Animator = GetComponent<Animator>();
    16.         m_Rigidbody = GetComponent<Rigidbody>();
    17.     }
    18.         void FixedUpdate()
    19.     {
    20.         float horizontal = Input.GetAxis("Horizontal");
    21.         float vertical = Input.GetAxis("Vertical");
    22.         m_Movement.Set(horizontal, 0f, vertical);
    23.         m_Movement.Normalize();
    24.         bool hasHorizontalInput = !Mathf.Approximately(horizontal, 0f);
    25.         bool hasVerticalInput = !Mathf.Approximately(vertical, 0f);
    26.         bool isWalking = hasHorizontalInput || hasVerticalInput;
    27.         m_Animator.SetBool("IsWalking", IsWalking);
    28.         Vector3 desiredForward = Vector3.RotateTowards(transform.forward, m_Movement, turnSpeed * Time.deltaTime, 0f);
    29.         m_Rotation = Quaternion.LookRotation(desiredForward);
    30.     }
    31.      void OnAnimatorMove()
    32.     {
    33.         m_Rigidbody.MovePosition(m_Rigidbody.position + m_Movement * m_Animator.deltaPosition.magnitude);
    34.         m_Rigidbody.MoveRotation(m_Rotation);
    35.     }
    36. }
    37.  
    Be easier if I had an error to share , but no. Any screenshots anyone needs I can happily share

    ty
     
    Last edited: May 18, 2019