Vigaca
Vigaca

Reputation: 25

Why is my character going through walls in Unity

I made simple character with first person movement. I'm not using CharacterController since I won't have more control over its physics. Characters' Rigidbody isn't kinematic and all the collision matrixes are correct in project editor, but player still goes through the walls. This is how I'm moving the character:

playerRb.MovePosition(transform.position + (transform.forward * Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime) + (transform.right * Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime));

And this is my characters' Rigidbody component: Rigidbody component screenshot

Upvotes: 0

Views: 381

Answers (1)

KYL3R
KYL3R

Reputation: 4073

Rigidbody.MovePosition is only for kinematic rigidbodies and ignores physics. Docs say:

Moves the kinematic Rigidbody towards position.

documentation

And older docs even said:

If the rigidbody has isKinematic set to false, it works like transform.position=newPosition and teleports the object to the new position (rather than performing a smooth transition).

(according to this forum entry)

So I would suggest that you simply set a velocity in the desired direction. If you need help with that, comment where you have difficulties and I will help you.

Upvotes: 2

Related Questions