So I know that you can get the velocity from the rigidBody. And I tried this. The problem I’m having, is that when I collide with an object, blocking the player, the velocity doesn’t come back as 0, instead it is as if the player never stopped moving. Same thing happen’s in reverse, when something collides with the player, causing it to move, the rigidBody.velocity still returns as greater than zero. Same thing happens in reverse. So when an object collides with the player while the player is standing still, causing it to move, the velocity returns as 0. I’m guessing it is because I change the velocity parameter of the player using the on screen controls. So how can I make it so that the player’s speed comes back as 0 when he collides with something, and also make it not come back as zero when something else pushes the player?
I tried using:
speed = (transform.position - lastPosition).magnitude / Time.deltaTime;
lastPosition = transform.position;
But if I put it in the Update, it mostly comes back as 0 regardless if the player is moving or not. In LateUpdate, it will come back as zero every other Update. And in the FixedUpdate, it will work correctly for like 2 seconds, but then it starts throwing 2’s for no reason.