Collision problem (41947)

Hello everyone,

I have a problem to handle collisions in my FPS game (yes, annoying for an FPS game -_-).

A projectile shot has a mesh collider (with a mesh and a trigger) and a rigidbody.

My floor and walls are in one piece (modelized with Maya), and have a mesh collider (with the corresponding mesh).

The following code is associated to the projectile :

function OnTriggerEnter (other:Collider)
{
	Debug.Log("Touché : " + other.name);
}

For now what I want to do is clearly the basics of colliders. But nothing is displayed when I shoot against a wall, but I can shoot myself (understand the FPS controller prefab we can use by default in Unity) and see my name displayed. I suppose there is a component missing in the walls but I thought the mesh collider was enough … Apparently not :frowning:

Are you sure you want to use OnTriggerEnter() in this case? [OnCollisionEnter()][1] might be of better use. [1]: http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html

–

I tried that too, with same objects (projectile with mesh collider & rigidbody and walls with mesh collider only) and this code : function OnTriggerEnter (other:Collider) { Debug.Log("OnTriggerEnter"); } function OnCollisionEnter(collision : Collision) { Debug.Log("OnCollisionEnter" ); } I only go in OnTriggerEnter while i'm shooting myself and nothing happens when i shoot on a wall.

–

3 Answers

3

Mmmh, I found my solution thanks to :
http://answers.unity3d.com/questions/46077/ontriggerenter-problem.html

I had a projectile with a mesh collider, the trigger and a rigidbody and my walls with a mesh collider.

I removed the mesh collider from the projectile and I put instead a box collider (not quite exactly the shape, but it will do the work …

A trigger for a wall does seems strange, As you’re probably not playing a ghost. The probleme must come from the fact that the projectile is traveling too fast for the collision to happen. You can either modify the collision detection of the rigidody, but it’s going to be expensive performance wise. Try using raycast to detect the collision instead of On(…)Enter(). Or make sure the projectile’s layer and the wall’s layer can collide in the physic settings.

And you sound french, so salut compatriote :slight_smile:

Yes I am ^^. I don't put the trigger on the wall, but only on the projectile. I also thought about the speed problem, to be sure, I shot in a way that the projectile touches all its way long a face of the wall, and nothing changes. I don't know much on raycast yet, and maybe this way works, but I don't understand why this method does not ...

–

And of course my problem is with an arrow :D So if I get it, we can go in OnTriggerEnter method only if : - one object has a mesh collider, isTrigger enabled and has the attached script on it. - one other has a mesh collider and a rigidbody. Is that it ?

–

The collider doesn't have to be a mesh one, can be box, caps etc. But yes, they must both have a collider and the movement must be induced by a physical force, that's why you need the rigidbody. A character controller using Move() or SimpleMove would work as well, as they are physic too.

–

Try making a box collider for the wall and in order for OnCollisionEnter to work the object must use a rigidbody to work. Also take the trigger of off the ball.

Is OnCollisionEnter working only with rigidbodies in both interstecting objects ? I find it weird to have to put a rigidbody on objects that are not moving at all in the scene

–