Skip to main content
Add more clearer solution to OP racing game case, in which no one cares anyway
Source Link
Wappenull
  • 638
  • 9
  • 18

SPOILER

You still CANNOT check for "source" trigger collider that triggers OnTriggerEnter, at least today or what I know at the time of writing (2020). But there is workaround.

For your racing game case

(This is 4 years after, you probably finished and mastered your cool racing game :). But I will include a specific answer to your question here, since it is manner for SO site, but I will keep it brief.)

Your racing game case is more trivial, since OnTriggerEnter( Collider other ) offers information on other sideobject, youin this case the checkpoint being hit. You could identify checkpoint in some way, such as its name "Checkpoint1". Store and process it on your racing car player object, such as putting it in List, HashSet, or anything, check to prevent duplication so that it run once.

If you need more detailed checkpoint object, such as passing this checkpoint will extend timer by +60sec. You could make a Checkpoint MonoBehaviour Component and attach that to checkpoint object, add any properties you want. Then on player car when collide with these checkpoints, GetComponent<Checkpoint>, process your checkpoint, again save it in List, HashSet to prevent duplication.

For detecting trigger source

Now the fun part. First, you need to understand nature of how physics engine call those events. I recommend to skim over this official document also:

The following are not stated in document but they are from what I observed:

  • If 2 colliders are on same game object, it acts as compound colliders. OnTrigger*** will called once.
  • If each collider is on different game object, such as parent-child (OP's case). OnTrigger*** will called once for each.
  • First OnTrigger will called on-site of the source trigger (if there is script with OnTrigger*** on it),
  • Then event will "bubble up" along the way and called on first RigidBody it reaches.

In both way, you still wont be able to know source trigger, because all events lead to one OnTriggerEnter( Collider other ) which provide no source information at all.

enter image description here

You need to distribute relay/satellite scripts to each trigger collider. Some example or discussion, see:

This way, if we can catch OnTrigger*** first hand at source game object, we can know source trigger collider. Application such as detecting head shot, leg shot, arm shot is now possible.

To prevent event bubbling

Sometimes you don't want event to bubbling up. For example, player can use their attack (which parented to player object) to cut down the flying arrow. With normal event bubbling, when slash attack meets with arrow, signal will bubble to player's rigidbody as if his slash is extending player's own collision! (bad)

In such case, you don't want trigger event to bubble up to player game object. This is done by inserting kinematic rigidbody into slash attack, disconnecting it to form its own collision group.

enter image description here

SPOILER

You still CANNOT check for "source" trigger collider that triggers OnTriggerEnter, at least today or what I know at the time of writing (2020). But there is workaround.

For your racing game case

(This is 4 years after, you probably finished and mastered your cool racing game :). But I will include a specific answer to your question here, since it is manner for SO site, but I will keep it brief.)

Your racing game case is more trivial, since OnTriggerEnter( Collider other ) offers information on other side, you could identify checkpoint in some way, such as its name "Checkpoint1". Store and process it on your racing car player object so that it run once.

For detecting trigger source

Now the fun part. First, you need to understand nature of how physics engine call those events. I recommend to skim over this official document also:

The following are not stated in document but they are from what I observed:

  • If 2 colliders are on same game object, it acts as compound colliders. OnTrigger*** will called once.
  • If each collider is on different game object, such as parent-child (OP's case). OnTrigger*** will called once for each.
  • First OnTrigger will called on-site of the source trigger (if there is script with OnTrigger*** on it),
  • Then event will "bubble up" along the way and called on first RigidBody it reaches.

In both way, you still wont be able to know source trigger, because all events lead to one OnTriggerEnter( Collider other ) which provide no source information at all.

enter image description here

You need to distribute relay/satellite scripts to each trigger collider. Some example or discussion, see:

This way, if we can catch OnTrigger*** first hand at source game object, we can know source trigger collider. Application such as detecting head shot, leg shot, arm shot is now possible.

To prevent event bubbling

Sometimes you don't want event to bubbling up. For example, player can use their attack (which parented to player object) to cut down the flying arrow. With normal event bubbling, when slash attack meets with arrow, signal will bubble to player's rigidbody as if his slash is extending player's own collision! (bad)

In such case, you don't want trigger event to bubble up to player game object. This is done by inserting kinematic rigidbody into slash attack, disconnecting it to form its own collision group.

enter image description here

SPOILER

You still CANNOT check for "source" trigger collider that triggers OnTriggerEnter, at least today or what I know at the time of writing (2020). But there is workaround.

For your racing game case

(This is 4 years after, you probably finished and mastered your cool racing game :). But I will include a specific answer to your question here, since it is manner for SO site, but I will keep it brief.)

Your racing game case is more trivial, since OnTriggerEnter( Collider other ) offers information on other object, in this case the checkpoint being hit. You could identify checkpoint in some way, such as its name "Checkpoint1". Store and process it on your racing car player object, such as putting it in List, HashSet, or anything, check to prevent duplication so that it run once.

If you need more detailed checkpoint object, such as passing this checkpoint will extend timer by +60sec. You could make a Checkpoint MonoBehaviour Component and attach that to checkpoint object, add any properties you want. Then on player car when collide with these checkpoints, GetComponent<Checkpoint>, process your checkpoint, again save it in List, HashSet to prevent duplication.

For detecting trigger source

Now the fun part. First, you need to understand nature of how physics engine call those events. I recommend to skim over this official document also:

The following are not stated in document but they are from what I observed:

  • If 2 colliders are on same game object, it acts as compound colliders. OnTrigger*** will called once.
  • If each collider is on different game object, such as parent-child (OP's case). OnTrigger*** will called once for each.
  • First OnTrigger will called on-site of the source trigger (if there is script with OnTrigger*** on it),
  • Then event will "bubble up" along the way and called on first RigidBody it reaches.

In both way, you still wont be able to know source trigger, because all events lead to one OnTriggerEnter( Collider other ) which provide no source information at all.

enter image description here

You need to distribute relay/satellite scripts to each trigger collider. Some example or discussion, see:

This way, if we can catch OnTrigger*** first hand at source game object, we can know source trigger collider. Application such as detecting head shot, leg shot, arm shot is now possible.

To prevent event bubbling

Sometimes you don't want event to bubbling up. For example, player can use their attack (which parented to player object) to cut down the flying arrow. With normal event bubbling, when slash attack meets with arrow, signal will bubble to player's rigidbody as if his slash is extending player's own collision! (bad)

In such case, you don't want trigger event to bubble up to player game object. This is done by inserting kinematic rigidbody into slash attack, disconnecting it to form its own collision group.

enter image description here

Update by further experiment by my own.
Source Link
Wappenull
  • 638
  • 9
  • 18

SPOILER

You still CANNOT check for "source" trigger collider that triggers OnTriggerEnter, at least today or what I know at the time of writing (2020). But there is workaround.

For your racing game case

(This is 4 years after, you probably finished and mastered your cool racing game :). But I will include a specific answer to your question here, since it is manner for SO site, but I will keep it brief.)

Your racing game case is more trivial, since OnTriggerEnter( Collider other ) offers information on other side, you could identify checkpoint in some way, such as its name "Checkpoint1". Store and process it on your racing car player object so that it run once.

For detecting trigger source

Now the fun part. First, you need to understand nature of how physics engine call those events. I recommend to skim over this official document also: https://docs.unity3d.com/Manual/CollidersOverview.html

The following are not stated in document but they are from what I observed:

  • If 2 triggerscolliders are on same game object, it acts as compound colliders. OnTrigger*** will called once.
  • If each triggercollider is on different game object, such as parent-child (OP's case) it is composite case. OnTrigger*** will called once for eachonce for each. But if for example, child object does not have
  • First OnTrigger will called on-site of the source trigger (if there is script forwith OnTrigger*** on it), it
  • Then event will "bubble up" to rigidbody, if exists in parent node. Thus appear as second callalong the way and called on script attached to rigidbody's levelfirst RigidBody it reaches.

In both way, you still wont be able to know source trigger, because all events lead to one OnTriggerEnter( Collider other ) which provide no suchsource information at all.

enter image description here

You need to distribute relay/satellite scripts to each trigger collider. Some example or discussion, see:

https://forum.unity.com/threads/checking-for-a-specific-collider-solved.815118/

This way you, if we can detectcatch OnTrigger*** first hand at source ofgame object, we can know source trigger collider. Application such as detecting head shot, leg shot, arm shot is now possible.

To prevent event bubbling

Sometimes you don't want event to bubbling up. For example, player can use their attack (which parented to player object) to cut down the flying arrow. With normal event bubbling, when slash attack meets with arrow, signal will bubble to player's rigidbody as if his slash is extending player's own collision! (bad)

In such case, you don't want trigger event to bubble up to player game object. This is done by inserting kinematic rigidbody into slash attack, disconnecting it to form its own collision group.

enter image description here

SPOILER

You still CANNOT check for "source" trigger collider that triggers OnTriggerEnter, at least today or what I know at the time of writing (2020). But there is workaround.

For your racing game case

(This is 4 years after, you probably finished and mastered your cool racing game :). But I will include a specific answer to your question here, since it is manner for SO site, but I will keep it brief.)

Your racing game case is more trivial, since OnTriggerEnter( Collider other ) offers information on other side, you could identify checkpoint in some way, such as its name "Checkpoint1". Store and process it on your racing car player object so that it run once.

For detecting trigger source

Now the fun part. First, you need to understand nature of how physics engine call those events. I recommend to skim over this official document also: https://docs.unity3d.com/Manual/CollidersOverview.html

The following are not stated in document but they are from what I observed:

  • If 2 triggers are on same game object, it acts as compound colliders. OnTrigger*** will called once.
  • If each trigger is on different game object, such as parent-child (OP's case) it is composite case. OnTrigger*** will called once for each. But if for example, child object does not have script for it, it will "bubble up" to rigidbody, if exists in parent node. Thus appear as second call on script attached to rigidbody's level.

In both way, you still wont be able to know source trigger, because all events lead to one OnTriggerEnter( Collider other ) which provide no such information at all.

You need to distribute relay/satellite scripts to each trigger collider. Some example or discussion, see:

https://forum.unity.com/threads/checking-for-a-specific-collider-solved.815118/

This way you can detect source of trigger collider. Application such as detecting head shot, leg shot, arm shot is now possible.

SPOILER

You still CANNOT check for "source" trigger collider that triggers OnTriggerEnter, at least today or what I know at the time of writing (2020). But there is workaround.

For your racing game case

(This is 4 years after, you probably finished and mastered your cool racing game :). But I will include a specific answer to your question here, since it is manner for SO site, but I will keep it brief.)

Your racing game case is more trivial, since OnTriggerEnter( Collider other ) offers information on other side, you could identify checkpoint in some way, such as its name "Checkpoint1". Store and process it on your racing car player object so that it run once.

For detecting trigger source

Now the fun part. First, you need to understand nature of how physics engine call those events. I recommend to skim over this official document also:

The following are not stated in document but they are from what I observed:

  • If 2 colliders are on same game object, it acts as compound colliders. OnTrigger*** will called once.
  • If each collider is on different game object, such as parent-child (OP's case). OnTrigger*** will called once for each.
  • First OnTrigger will called on-site of the source trigger (if there is script with OnTrigger*** on it),
  • Then event will "bubble up" along the way and called on first RigidBody it reaches.

In both way, you still wont be able to know source trigger, because all events lead to one OnTriggerEnter( Collider other ) which provide no source information at all.

enter image description here

You need to distribute relay/satellite scripts to each trigger collider. Some example or discussion, see:

This way, if we can catch OnTrigger*** first hand at source game object, we can know source trigger collider. Application such as detecting head shot, leg shot, arm shot is now possible.

To prevent event bubbling

Sometimes you don't want event to bubbling up. For example, player can use their attack (which parented to player object) to cut down the flying arrow. With normal event bubbling, when slash attack meets with arrow, signal will bubble to player's rigidbody as if his slash is extending player's own collision! (bad)

In such case, you don't want trigger event to bubble up to player game object. This is done by inserting kinematic rigidbody into slash attack, disconnecting it to form its own collision group.

enter image description here

Source Link
Wappenull
  • 638
  • 9
  • 18

SPOILER

You still CANNOT check for "source" trigger collider that triggers OnTriggerEnter, at least today or what I know at the time of writing (2020). But there is workaround.

For your racing game case

(This is 4 years after, you probably finished and mastered your cool racing game :). But I will include a specific answer to your question here, since it is manner for SO site, but I will keep it brief.)

Your racing game case is more trivial, since OnTriggerEnter( Collider other ) offers information on other side, you could identify checkpoint in some way, such as its name "Checkpoint1". Store and process it on your racing car player object so that it run once.

For detecting trigger source

Now the fun part. First, you need to understand nature of how physics engine call those events. I recommend to skim over this official document also: https://docs.unity3d.com/Manual/CollidersOverview.html

The following are not stated in document but they are from what I observed:

  • If 2 triggers are on same game object, it acts as compound colliders. OnTrigger*** will called once.
  • If each trigger is on different game object, such as parent-child (OP's case) it is composite case. OnTrigger*** will called once for each. But if for example, child object does not have script for it, it will "bubble up" to rigidbody, if exists in parent node. Thus appear as second call on script attached to rigidbody's level.

In both way, you still wont be able to know source trigger, because all events lead to one OnTriggerEnter( Collider other ) which provide no such information at all.

You need to distribute relay/satellite scripts to each trigger collider. Some example or discussion, see:

https://forum.unity.com/threads/checking-for-a-specific-collider-solved.815118/

This way you can detect source of trigger collider. Application such as detecting head shot, leg shot, arm shot is now possible.