- Home /
Question about collision and trigger
Hi! I have done a game and have some problem about that. If a ball (Tag as player) hit the pipe(Tag as standard pipe), the ball will return to starting point(A empty object tag as respawn).
How can I write it? Should I need to tick the trigger box?(Ball have a rigid body)
Answer by Owen-Reynolds · Apr 19, 2012 at 03:18 PM
Take a look at the scripting reference for collisions. http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html
has an example. Then browse around for those terms and you'll find plenty more examples like that and general info on colliders, triggers and so forth.
In general, Triggers and Colliders can both detect what "hits" them. Use a Collider for a "real" object, which most things bounce off of. Use a trigger for a "zone" (around a fire?, entrance to the library, ... )
You have your choice of whether the pipe detects when the player hits it (would need to add a script to the pipe, or add to existing one,) or whether the player detects when it hits the pipe.
If the ball is using a characterController (which is odd for a ball,) then you have to use a special one, that only works on the sphere. http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.html
has the list of the "what happened this frame" functions. Take a look at OnCharControllerHit. There's an example.
Answer by Wesker_Kai · Apr 19, 2012 at 04:43 PM
know there are many example, but the main problem is THERE ARE TOO MANY EXAMPLE!!! 2.Your explain of Triggers and Colliders are really outstanding. 3.That means I need 2 script?
If you can, try to put replies to an "answer" as comments on that answer. Helps for when someone else is searching through later.
"That means I need 2 script": See my 3rd paragraph. Only one place needs to check for the collision.
Your answer
Follow this Question
Related Questions
If trigger hit, spawn it 1 Answer
Compound collider object behaving as a whole? 1 Answer
OnTriggerStay2D with many colliders 1 Answer
OnTrigger outside the trigger and collider gamobject 1 Answer
collider doesnt work the 2nd time 1 Answer