Hi,
I am writing a subway surfer’s like game which uses a character with constant movement.
I also want to have instant left/right movement (aka. no force).
I am doing both with this snippet:
Vector3 vel = this.rigidbody.velocity;
float hAxis = CustomInput.GetHorizontalAxis();
vel.z = _currentFowardVelocity; // 8.0f
vel.x = hAxis * _currentHorzintalVelocity; // max 8.0f
this.rigidbody.velocity = vel;
// gravity
this.rigidbody.AddForce(25f * Vector3.down);
I set the Rigidbody Collision Detection to “Continuous” to
deal with the increased gravity.
But I still get issues with my rigidbody entering other fixed
objects and being stuck in them:
The rigidbody is a capsule collider and it’s stuck in a fixed
box collider in the picture abvoe. The physics material (dynamic|static) friction and
bounciness is set to 0.
Questions:
-
Is setting the constant velocity responsible for this behaviour?
-
How do I fix this?
Note that I can avoid this issue by enlarging the capsule collider, but
then it doesn’t feel right since it’s way bigger than the board which it
should represent.
Thanks