Player bounce when not supposed to
void Movement(Vector2 move, bool yMovement)
{
float distance = move.magnitude;
if (distance > minMoveDistance)
{
int count = rb2d.Cast(move, ContactFilter, hitBuffer, distance + shellRadius);
hitBufferList.Clear();
for(int i = 0; i < count; i++)
{
hitBufferList.Add (hitBuffer[i]);
}
for (int i = 0; i < hitBufferList.Count; i++)
{
Vector2 currentNormal = hitBufferList[i].normal;
if (currentNormal.y > minGroundNormalY)
{
grounded = true;
if (yMovement)
{
currentNormal = groundNormal;
currentNormal.x = 0;
}
}
float projection = Vector2.Dot(velocity, currentNormal);
if (projection < 0)
{
velocity = velocity - projection * currentNormal;
}
float modifiedDistance = hitBufferList[i].distance - shellRadius;
distance = modifiedDistance < distance ? modifiedDistance : distance;
}
}
rb2d.position = rb2d.position + move.normalized * distance;
}
So my issue is that sometimes when my player hits a platform it will bounce of the ground making it immposible to jump again. How can I make shure that the player stays grounded until the jump button is pressed again, instad of bouncing for no reason?
Answer by tormentoarmagedoom · Jan 30, 2019 at 10:09 AM
Good day.
Most probably it bounce due to phicis material, or rigidbody collisions.
Best solution i think is when detect the ground, to force the rigidbody.velocity.y to 0 (the vertical component of the velocity)
rb = rigidbody
rb.velocity = new Vector3(rb.velocity.x, 0, rb.velocity.z);
This way it will continue advancing the same speed but vertical speed will be set to 0 during 1 frame, preventing the bounce.
Bye!
Your answer
Follow this Question
Related Questions
Why does my player bounce when hitting edge of platform 0 Answers
Ad is not ready, why???? 0 Answers
Can someone please tell me whats wrong with this?, because when i put it says error in the GetAxis 1 Answer
Player sticking walking around inside tunnel.. Raycast HOW? 0 Answers
Issue with Player Movement,Issue With Player movement 0 Answers