Object moving to other Axis

My character is not only moving to X upon my instruction, it is moving to Y and Z as well, following is my code, appreciate somebody could advise.

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

public class Player1move : MonoBehaviour
{
private Animator Anim;
[SerializeField] public float WalkSpeed = 0.01f;

// Start is called before the first frame update
void Start()
{
    Anim = GetComponentInChildren<Animator>();
}

// Update is called once per frame
void Update()
{
    // Walking left and right
    if(Input.GetAxis("Horizontal") > 0)
    {
        Anim.SetBool("forward", true);
        transform.Translate(WalkSpeed, 0,0);
    }
    if (Input.GetAxis("Horizontal") < 0)
    {
        Anim.SetBool("backward", true);
        transform.Translate(-WalkSpeed, 0, 0);
    }
    if (Input.GetAxis("Horizontal") == 0)
    {
        Anim.SetBool("forward", false);
        Anim.SetBool("backward", false);
    }
    // Jumping and bending
    if (Input.GetAxis("Vertical") > 0)
    {
        Anim.SetTrigger("jump");
    }
    if (Input.GetAxis("Vertical") < 0)
    {
        Anim.SetBool("bend", true);
    }
    if (Input.GetAxis("Vertical") == 0)
    {
        Anim.SetBool("bend", false);
    }
}

}

At a guess, your animation is moving your gameObject.

Thanks, any solution? Please forgive me coz I’m still learning.

Unfortunately, it’s one of those, “Depends on what you’ve done” kind of answers.

You do often see if when people animate the position of the base game object instead of animating the position of a child object. If that’s the case, put what you want animated in a child object and animate that instead.

Found the solution, thanks!
Object moving to other Axis 1

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

Privacy & Terms