- Home /
Mesh Collider Does Not Working
I have a player and an enemy . I want to detect collision between player and enemy.
for that ,
I have a player with rigidbody and mesh collider.
-> set rigidbody iskinematic to true.
-> set mesh collider convex to true.
I have enemy with sphere collider.
-> isTrigger is set to true.
Script attached to my player is here:
function OnTriggerEnter(otherObject : Collider)
{
Debug.Log("Hit player");
if(otherObject.tag == "AirCraft")
{
Instantiate(blastPrefab , transform.position , Quaternion.identity);
var es : Enemy = otherObject.gameObject.GetComponent("Enemy");
es.SetPositionandSpeed();
Destroy(gameObject);
}
}
But still collision is not detected,.. What is missing ??
Please Help me.
Thanks for your support and help in advance,..
just fyi as a general rtule you never use mesh colliders in video games. just use simple primitives like cube, sphere etc.
Answer by Chronos-L · Mar 29, 2013 at 06:37 AM
By this setup, the OnTriggerEnter
will be called when your player is moved to your enemy; if you move your enemy to the player, nothing will happen.
Look at this page.
The player is a Kinematic-rigidbody-collider, while your enemy is a static-trigger. They will work as long as the player is the one moving. A static trigger (the enemy) moving around will not active any trigger
-event, because they are supposed to be not moving (static).
If you want to move your enemy and be able to active the OnTriggerEnter()
, then make the enemy a rigidbody-trigger or a kinematic-rigidbody-trigger.
how do i make my enemy rigidbody trigger or kinematic rigidbody trigger? i want my enemy to move and want to active trigger.
change :
I make my enemy with rigidbody. -> set iskinematic to true.
I kept my player with mesh collider -> istrigger to true and convex is also true.
Now what do i need to do??
Your current setup:
Enemy ($$anonymous$$inematic Rigidbody Collider)
Collider
Rigidbody : is$$anonymous$$inematic
Player (Static Trigger Collider)
Collider : isTrigger
So, your player no longer have the rigidbody? If so, then the OnTriggerEnter()
will be called only when the enemy is moved to the player, but not the other way around (when player is moved to enemy)
Check this out might you got some idea--->Absolute Beginners guide to Unity 3D Game Objects and Box Colliders
Cheers from INDIA......
but my object is consu$$anonymous$$g more than one mesh then how do i assign ??
If it is not animated, use modelling software to model a simplified shape of the your current object. Use it as the collision mesh.
If it is animated, depending on how complex the animation is, you can still use the first solution if it is not so complex, or else you will need to built a compound collider.