0
votes

I'm building a VR maze game for Google Cardboard with the https://github.com/JuppOtto/Google-Cardboard/blob/master/Autowalk.cs as the script which moves the player. So far I've found nothing that will help me and I've tried messing around with physics materials, freezing/unfreezing constraints of my Rigidbody, setting angular drag to infinity, etc.

As I've learned, the problem should be that my Rigidbody is penetrating the walls that have mesh colliders on them and it gets pushed back out which results in this weird "bouncy behavior". It almost feels like the Rigidbody character is continuously trying to go through the walls even though it can't.

For the most part this wouldn't be too big of an issue, but there are some corners in the game that have other smaller objects that also have mesh colliders on them and should the player get in between these objects and the walls, they would simply be pushed (bounced) out of the game area and through the walls altogether.

Here's the bit that is responsible for the movement of my character and I believe this has to be changed to something else:

if (isWalking) 
{
    Vector3 direction = new Vector3(head.transform.forward.x, 0, head.transform.forward.z).normalized * speed * Time.deltaTime;
    Quaternion rotation = Quaternion.Euler(new Vector3(0, -transform.rotation.eulerAngles.y, 0));
    transform.Translate(rotation * direction);
}

And here's some information on my setup:

Character that has the movement script has a capsule collider and a Rigidbody with mass: 1; drag and angular drag: 0; is using gravity, is not kinematic, interpolate is set to none with collision detection set to discrete. Position is not frozen, but the rotation is for all X, Y and Z coordinates so it wouldn't fall over.

The walls (3D model) have a simple mesh collider on them, nothing more.

I think I should also mention that I don't want the character to just stop when it collides with the walls and therefore I don't think using triggers and such is a good idea. Stopping completely is only acceptable when the player collides with a wall as they're facing it straight, but if there's an angle, I would like the player to "slide" along the wall.

2

2 Answers

1
votes

You can also remove the Rigidbody component and instead use the CharacterController component on your player and use the SimpleMove function instead of translating the player. The Translate function sets the player on a new Vector position, which would make the player intersect with walls instead of colliding with them.

0
votes

You'll have to turn on interpolation (set it to Interpolate) and set isKinematic on your rigidbody and use Rigidbody.MovePosition instead. MovePosition interpolates to the given position and does not allow the Rigidbody to pass through objects. Setting transform.position or Rigidbody.position teleports the Rigidbody instead, which can be undesirable.

You can also chuck the Rigidbody and use a CharacterController instead, which makes it much easier to move characters without having to deal with rigidbodies all the time.