Movement Input

I have set up the character movement like it is in the lecture, but the player does not move with stateMachine.transform.Translate or stateMachine.Controller.Move.

The player has Input Reader and Player State Machine scripts.

Using Debug.Log the x and y directions in the console show up.

Paste in your PlayerFreelookState.cs and we’ll take a look.

In this point of the course there is not a script called PlayerFreelookState. Probably the closest is PlayerTestState.cs that looks like this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerTestState : PlayerBaseState
{
    public PlayerTestState(PlayerStateMachine stateMachine) : base(stateMachine) {}

    public override void Enter()
    {

    }

    public override void Tick(float deltaTime)
    {
        Vector3 movement = new Vector3();
        movement.x = stateMachine.InputReader.MovementValue.x;
        movement.y = 0;
        movement.z = stateMachine.InputReader.MovementValue.y;
        stateMachine.Controller.Move(movement * stateMachine.FreeLookMovementSpeed * deltaTime);

        if (stateMachine.InputReader.MovementValue == Vector2.zero) { return; }

        stateMachine.transform.rotation = Quaternion.LookRotation(movement);
    }

    public override void Exit()
    {

    }
}

Quite right, misgauged how far this lecture is in the course.

Let’s put a more informative Debug just before the stateMachine.Controller.Move() call.:

Debug.Log($"Move: Input = {InputReader.MovementValue}.  Movement = {movement}.  Speed = {stateMachine.FreeLookMovementSpeed}  Controller.Move({movement*stateMachine.FreeLookMovementSpeed * deltaTime})";

Small changes were needed:
Debug.Log($“Move: Input = {stateMachine.InputReader.MovementValue}. Movement = {movement}. Speed = {stateMachine.FreeLookMovementSpeed} Controller.Move({movement * stateMachine.FreeLookMovementSpeed * deltaTime})”);

The new Debug.Log did work and at first showed all 0, but I added the script to a new character (cube) and it worked (cube moved). Turns out the problem is the animator. Once I disabled it, the original player character moved (in a T pose). When enabling root motion on animator the character moves while having an animation.

Added the player character under a new empty object that has all the code and character controller. Kept the animator on the original player with root motion disabled.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms