My character always slides across the screen and I can’t figure it out. Any ideas?
Change the input manager settings for gravity, etc.
–Eric
Are you using Input.GetAxis? It applies a little smoothing when using keyboard controls so that values don’t change instantaneously. Try using Input.GetAxisRaw instead.
I changed Input.GetAxis and there is still no difference, input manager didn’t change anything either unless I did something wrong with it.
Are you moving by adding forces?
Yes
In that case, the reason it keeps moving is simply momentum. One solution would be to move using Rigidbody2D.MovePosition: Unity - Scripting API: Rigidbody2D.MovePosition Another would be to substantially increase the drag.
Here’s my solution:
var h:int; //reference variable for horizontal axis
function Update()
{
if(Input.GetButton("Left")||Input.GetAxis("LThumbstick Left/Right")<0)
h=-1;
else if(Input.GetButton("Right")||Input.GetAxis("LThumbstick Left/Right")>0)
h=1;
else
h=0;
if(h==0)
rigidbody2D.velocity=Vector2(0,rigidbody2D.velocity.y); //if you're not pushing left/right it will stop you on a dime without changing the Y velocity so you can still fall.
}
Thanks man.
Thanks, this works wonders for my game
9 years later, and this still saved my day. Thanks a bunch
Also, if others are new to this, the gravity and sensitivity settings is not related to gravity in physics. (I first understood that when I read this)
Please stop necroing posts.