2
\$\begingroup\$

I am working on a Unity 3D game for Oculus and I have problems with making my objects to apply physics on a player. So getting rid of a CharacterController and using something like a rag doll is not an option.

I am using OVRPlayerController, that has a Rigidbody with mass 1 and a box collider on it. My gameObject has a Rigidbody of mass 100, and a box collider. But when the object hits the player it just goes through it, whereas I want it to push the player in x direction.

I tried using onColliderHit but it doesn't even recognize the collision between the player and the object, so I checked box collider on the object to be a trigger and I use OnTriggerEnter() to recognize the collision.

I tried to translate the player's position on collision, but player gets positioned to weird places out of my map for some reason. Here is what I use:

 info.transform.Translate(new Vector3( -0.5f, 0.0f, 0.0f));
 info.transform.rotation = Quaternion.identity;

I also tried to manually set the x position of the player but this doesn't work, and I know I am not supposed to do it.

I searched for answers for a long long time, so please don't answer to this with something like "oh, have you tried googling it, there are a lot of similar questions" etc.

\$\endgroup\$
  • \$\begingroup\$ maybe you should uncheck "is trigger" on your colliders \$\endgroup\$ – Leggy7 Apr 3 '15 at 17:01
  • \$\begingroup\$ is your player's rigidbody marked as isKinematic? If so I don't think it'll move. \$\endgroup\$ – Tetrad Apr 3 '15 at 19:14
1
\$\begingroup\$

Have you tried using ControllerColliderHit.transform

void OnControllerColliderHit(ControllerColliderHit hit) 
{
    Debug.Log("I'm colliding with: " + hit.transform.name);
}
\$\endgroup\$
  • \$\begingroup\$ I added that to my camera script. It never gets called. For some reason I cannot recognize collisions but I recognize all the triggers. Even though I collide with objects who have colliders on it. \$\endgroup\$ – romada Mar 5 '15 at 0:34
  • \$\begingroup\$ @romada Don't add that to camera, add it to the OVRCharactercontroller object. That's the one that has a capsule collider and rigidbody. \$\endgroup\$ – SanSolo Nov 1 '15 at 18:22
1
\$\begingroup\$

Objects shouldn't pass through each other if both have colliders. You could disable isKinematic on the rigidbody and then use AddForce to push. You could use also transform.translate() to move the player.

\$\endgroup\$
1
\$\begingroup\$

I tried using onColliderHit but it doesn't even recognize the collision between the player and the object

There's no such method. There are following methods for collision detection:

  1. Void OnCollisionEnter(Collision otherCollider)
  2. OnCollisionStay(Collision otherCollider)
  3. OnCollisionExit(Collision otherCollider)
  4. OnTriggerEnter(Collider otherCollider)
  5. OnTriggerStay(Collider otherCollider)
  6. OnTriggerExit(Collider otherCollider)

Note that parameters are completely optional unless you want to do something with that info.

\$\endgroup\$
0
\$\begingroup\$

My gameObject has a Rigidbody of mass 100

That could very well be the source of your problem. From Unity documentation :

You should strive to keep mass close to 0.1 and never more than 10. Large masses make physics simulation unstable

Even if this doesn't solve your current problem,it's good to follow advice from Unity themselves.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.