Player won't stop moving when key is released
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerController : MonoBehaviour { public float moveSpeed;
private Animator anim;
private bool playerMoveing;
private Vector2 lastMove;
// Start is called before the first frame update
void Start()
{
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
playerMoveing = false;
if (Input.GetAxisRaw("Horizontal") >0.5f || Input.GetAxisRaw("Horizontal") <-0.5f)
{
transform.Translate(new Vector3(Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime, 0f, 0f));
playerMoveing = true;
lastMove=new Vector2 (Input.GetAxisRaw("Horizontal"),0f);
}
if (Input.GetAxisRaw("Vertical") >0.5f || Input.GetAxisRaw("Vertical") <-0.5f)
{
transform.Translate(new Vector3(0f, Input.GetAxisRaw("Vertical") * moveSpeed * Time.deltaTime, 0f));
playerMoveing = true;
lastMove = new Vector2(0f, Input.GetAxisRaw("Vertical"));
{
anim.SetFloat("MoveX", Input.GetAxisRaw("Horizontal"));
anim.SetFloat("MoveY", Input.GetAxisRaw("Vertical"));
anim.SetBool("PlayerMoveing", playerMoveing);
anim.SetFloat("LastMoveX", lastMove.x);
anim.SetFloat("LastMoveY", lastMove.y);
}
can you test changing getaxis rather than getaxisraw? in case is not getting to 0 even when you release.
Answer by KevoGS · Feb 21, 2019 at 09:21 PM
Thanks for the reply, but unfortunately i didn‘t work out for me, the Character is still walking
can you debug.log the axis value in the update and tell us if its setting to 0?
Don´t understand what u exactly mean (sorry,newbie). Could you send me an example of how it should look like? @xxmariofer
Debug.Log(Input.GetAxis(Horizontal));
in the update. make sure the value is setting right to 0.
Your answer
Follow this Question
Related Questions
My 2d movement script isn't working 0 Answers
How to create a script for a vehicle fuel? 0 Answers
ArgumentOutOfRangeException is occuring when it shouldn't 0 Answers
Manual GUI Refresh 0 Answers