I currently have a small Problem with my game. And I really run out of ideas. I traced the problem to the velocity function of a rigid body.
Heres my code
Rigidbody2d player = GetComponent<Rigidbody2D>();
Update loop:
if (Input.GetMouseButton(0))
{
player.velocity = vector2.zero;
}
if (Input.GetMouseButtonUp(0)){
player.velocity = vector2.zero;
}
The GetMouseButton Function always works. But the GetMouseButtonUp only works sometimes. Both listeners are called just fine. I tested it by writing to the log if a listener was called.
But the velocity doesnt always seems to change.
Has anyone any idea?
N.B: speedx, speedy and speedz are my own arbitrary values, you can use whatever variable values you want.
This code can be improved but I’m pretty sure this will solve most of your problems. I hope I helped whoever was struggling with this(I too struggled with this before so I know your pain).
very weird glitch but here is how to fix it
just multiply by 0 rb.velocity = Vector3.zero * 0;
it doesn’t always work, but it makes the glitch A LOT more rare so yeah, hope it helped