- Home /
OnCollisionEnter and rigidbody problem
Hi, i have searched around theese forums for a solution for my collision problem but nothing works. I simply want my player to collide with a boat but nothing happens. Both objects are rigidbodys and have mesh colliders. The boat is tagged "Boat". I would like to destroy the boat when the player collides with it. Debug log doesn't respond either.
Everyone says I should use a script like this:
function OnCollisionEnter(collision:Collision)
{
if(collision.gameObject.tag == "Boat")
{
Debug.Log("Hit!");
}
}
Help would be appreciated :)
Is the player at least bouncing against the boat or is it going through? Do you have one collider set to IsTrigger?
Two $$anonymous$$eshColliders need extra work to collide with each other. As a test, give one (or both) just a box or sphere collider.
If that works, either read up on setting convex $$anonymous$$C's, or about making compound colliders (for a big, ugly mesh, sometimes easier to just cover it with some standard box and capsule colliders.)
i have no idea why but it works now. anyways, thanks for the reply.
maybe it was because i changes the collider to a box collider. $$anonymous$$esh collider doesn't seem to work for my model.
$$anonymous$$esh Colliders do not normally collide with other $$anonymous$$esh Colliders, as Owen above have stated. You'd have to go about making the $$anonymous$$C Convex, which is a separate topic altogether.
Answer by maroonrs2 · Apr 30, 2012 at 03:08 AM
function OnCollisionEnter (hit : Collision)
{
if(collision.gameObject.CompareTag("Boat"))
{
Debug.Log("Hit!");
}
}
make sure you tag your boat. Also make sure Is Kineticable is off, for this disables it.
But where have you defined the "collision"? But you have used it in the script. And you have defined "hit" and never used it! This is peculiar!
opps thanks for catching that lol. I ran into a problem with On not capatalized. and also CompareTag is the best way as you cannot read what .tag is and compare it at the same time.
Your answer
Follow this Question
Related Questions
Collision Only being detected on one of the objects involved in the collision - C# 0 Answers
what object hit me? easy rigidbody question 1 Answer
A bit confused with OnCollision and Rigidbodys 0 Answers
Rigidbody slightly intrudes another one while pushing it 1 Answer
Further collision beyond the OnCollisionEnter() event 1 Answer