Hello, I am having some trouble with triggers.
I am trying to get an object(object B) to rotate when it hits a trigger but its not wanting to cooperate. The object(object B) is set to follow another object(object A). The object(object A) being follow also hits the trigger and is rotating perfectly, I want the following object(object B) to do the same thing but it is just going through the trigger and not rotating at all.
So we have Object A and Object B hitting a trigger, Object A is rotating but Object B is not.
The following code is for the rotation of object B.
var target : Transform;
var distance = 0;
var height = 5;
var damping = 10;
function Update ()
{
var wantedPosition = target.TransformPoint(0, height, distance);
transform.position = Vector3.Lerp (transform.position, wantedPosition, Time.deltaTime * damping);
}
function OnTriggerEnter (collisionInfo : Collider)
{
if (collisionInfo.gameObject.tag == "FrontToLeft")
{
transform.Rotate(0,90,0);
}
}
Thanks for your help.
Dumb question… does Object B have the tag “FrontToLeft”?
If so, how are you moving Object B?
no the trigger is what is tagged “front to left”, not a dumb question, I am new to unity so all questions are good. is the tag my problem? it is working in the script for object A
1 Like
Put it this way: Does the object that you want to rotate have the “FrontToLeft” tag and is the trigger directly on that object or is it a child?
the trigger exists in the game world a few feet away from object A and B, it is tagged “FrontToLeft”. A and B move forward into the trigger and hit it at the same time, A rotates B does not. So no the object i want to rotate is not tagged “FrontToLeft”. and no the trigger is not on the object or a child of the object.
Ahh… I see it. You need to apply a script to the trigger that tells something to turn. You have it hitting something and telling it to turn when it hits something.
// moves the object
var target : Transform;
var distance = 0;
var height = 5;
var damping = 10;
function Update ()
{
var wantedPosition = target.TransformPoint(0, height, distance);
transform.position = Vector3.Lerp (transform.position, wantedPosition, Time.deltaTime * damping);
}
// on the trigger for "FrontToLeft"
var turnAmount=90.0;
function OnTriggerEnter (collisionInfo : Collider)
{
if (collisionInfo.gameObject.tag == "myObject"){
collisionInfo.gameObject.transform.Rotate(0,turnAmount,0);
}
}
This is very much like an old arcade game called Centipede. 
ok thanks for your help. centipede is great.
EDIT
ill post if this fixes the issues. thanks again.
I attached that to the trigger and it still had no effect on object B when it they collided. What I don’t understand is that the script on object A is virtual the same and it is rotating perfectly. Could it have something to do with the fact that object B is receiving information on where to be based off the vector3 of Object A?