maybe you just change velocity through .velocity = 1 (e.g and it just keeps at 1) or AddForce bla-bla ForceMode.Velocity and never get it back to zero when player stopped holding the button or the character physical material is zero friction?
maybe you can just ask free ChatGPT 3.5 that was unlimited to everyone even on OpenAI website as I know, or show the whole thing with the important logic parts, it is hard to get when a few lines what exactly you want and happening. You can even give it the script if its simple and ask for bugfix, improvement
You set your velocity whenever you hold one of your keys down, but you never set it back to 0. So of course it would not stop moving. What you probably want to do is this:
What do you then do with your MoveDirect? can you share that bit of code?
You said you want it to stop by lowering a key? so you want to press a key to stop?
I definately your code would help. As from that small snippet it looks like you are adding it to a position so, if you only set it to 2 or -2 when pressed then when not pressed it should auto stop, because it is no longer changing the position… hence, wondering what the rest of the code is
@FnSolo you really are obsessed with AI arent you AI is not bad, but understanding why your code doesnt do what you think is a valid thought process so I think we need to encourage @anadaly1 to understand why what they wrote hasnt done what they thought.
anyways moderator solved it i just didnt thought after he said about stop on lowering the key that it is that primitive as i thought Ed. and actually replied upper to set velocity back to zero
Ed. 2 Should’ve shown it in the else{} code not a tip
MoveDirect.x = 0;
if (Input.GetKey(KeyCode.D))
{
MoveDirect.x += 2;
}
if (Input.GetKey(KeyCode.A))
{
MoveDirect.x -= 2;
}
Here each if statement would add or subtract to / from the value. Here the behaviour would be when you press both buttons at the same time, you would get back to 0 as both if statements would be entered. One is adding 2 to 0 the other subtracting 2. So you’re back to 0.
Ah, so you mislead me and I fell for it, when i asked if you set it to zero you said yes, so you obviously arent doing it before this code to be a case of if no keys are pressed you arent moving… Hence the whole chunk of code would be usefu.
@Bunny83 did good by guessing you werent and what you did with your variables