Collision not working

I have a small project, I have a spawnpoint in a moving 2D level. When the level is being geenreated the spawnpoint spawns one of 2 Barriers. These barriers then get attached to the invisble spawnpoint as child object. This was done since the level is moving and the spawnpoint is part of a prefab which is moving. Now the Barriers are also moving exactly like the sapwnpoint. So far so good.

The Script fot this is:

var objs : GameObject[];

var SpawnPoint : Transform;

function Start () {

//Spawn Random Barrier at Spawnpoint var newObj = Instantiate(objs[(Random.Range(0, objs.Length))], SpawnPoint.position, Quaternion.identity);

// Make Barrier a Child of Spawnpoint so it moves with the Level newObj.transform.parent = SpawnPoint;


My Problem now is that I want the player to colide with these Barriers and if he is in the wrong state, he should die. The script for that is:

// collide with barrier and die

function OnTriggerEnter (collisionInfo : Collider) {

if (collisionInfo.gameObject.tag == "BarrierBlue"){




I did not implement the States yet since it is already a problem. The collision for the Barrier does not work. The Box Collider on the Barrier is set to Trigger and the Tag also fits. To be on the save side I even made the barrier 50 pixel wide on the Z Axis to make sure the character does not pass it without hitting it however the collision does no trigger....

Could there be a problem if I attach an object with collision to a different object as child ?

more ▼

asked Mar 12, 2012 at 03:42 PM

avatar image

101 58 53 56

Are there any rigidbodies involved? You need at least one rigidbody (on any object that moves) for collision detection of any sort to work properly.

Mar 12, 2012 at 03:57 PM syclamoth

Yes the player is a rigidbody, all collisions with every other object in the game work perfectly just with these barriers I am having huge problems

Mar 12, 2012 at 04:42 PM deathripper
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
  1. Make sure your tag is actually spelt 'BarrierBlue' i.e case sensitive

  2. Check the barrier has the correct tag assigned

  3. Also check you have attached the player script to your player object with the collider.

  4. Don't make your collider on your player a trigger, only make the collider on your barrier a trigger.

If all those are in place there is no reason why OnTriggerEnter won't work.

more ▼

answered Mar 13, 2012 at 07:14 PM

avatar image

6.6k 53 58 89

Checked everything about ten times already... the spawnpoint doesn't have any triggers or colliders, could that be a problem if the parent of a child which has colliders doesn't have any colliders ?

Mar 13, 2012 at 07:42 PM deathripper

What happens when you do a Debug.Log inside your OnTriggerEnter in your player script?

Mar 13, 2012 at 07:55 PM Meltdown

OK, I finally found something. the collision of the barrier only works if may player is jumping. if he is standing on the ground the collision just doesn't trigger. I have three different if statements in my OnTriggerEnter function all work just this one doesn't :-(

Mar 13, 2012 at 08:10 PM deathripper
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Mar 12, 2012 at 03:42 PM

Seen: 1049 times

Last Updated: Mar 13, 2012 at 08:10 PM