- Home /
Collision Enter one of the objects ?
Hello Again, I've been working on collision detecting. So Let me explain;
As following the code;
var collision1 : GameObject;
var collision2 : GameObject;
var collision3 : GameObject;
var collision4 : GameObject;
var collisionFollow1 : Transform;
var collisionFollow2 : Transform;
var collisionFollow3 : Transform;
var collisionFollow4 : Transform;
function Update () {
// I dont know :D
}
I'm gonna attach theese cubes as gameobjects and, x,y,z,t points as transform.
I don't know how to detect collision ? i mean;
if (Collision : collision1)
{
transform.LookAt(collisionFollow1);
//move forward stuff
}
if (Collision : collision2)
{
transform.LookAt(collisionFollow2);
//move forward stuff
}
.........
Please help :S
Answer by Xtro · Jan 29, 2014 at 03:37 PM
First of all, you shouldn't add more than one collider to a game object.
1) Put the colliders into separate objects.
2) Implement the OnTriggerEnter event on the moving object (maybe a spaceship)
3) When the event on the ship triggered, you can read the "other" parameter to decide which collider you've hit.
so the code will be similar to this:
function OnTriggerEnter(other : Collider)
{
if (other == collision1)
{
// do something
}
else if (other == collision2)
{
// do another thing
}
}
Can you please mark the correct answer if you fixed that problem?
Sorry I'was busy i newly seen your answer :S I would like to do this;
var collision1 : GameObject;
var collision2 : GameObject;
var collision3 : GameObject;
var collision4 : GameObject;
var collisionFollow1 : Transform;
var collisionFollow2 : Transform;
var collisionFollow3 : Transform;
var collisionFollow4 : Transform;
function OnTriggerEnter(other : Collider)
{
if (entered collider of the collision1)
{
transform.LookAt(collisionFollow1);
}
//and for other ones
}
Can you please mark this as a correct answer?
Turkish translation : $$anonymous$$olay gelsin kardeş. Zahmet olmazsa doğru cevap olarak işaretler misin ? :) :)