- Home /
gameobject teleports to random location
I am trying to make a game where a gameobject is constantly moving towards you, and the only way to keep it away if by shining it with a flashlight. I have a cube attached to the flashlight as a collider. I've been configuring this script for hours, but it still doesn't move the gameobject when the light collider hits it
Here is the script:
var destination:Vector3;
function OnTriggerEnter(other : Collider)
{
if(other.tag == "EvilFace")
{
destination=Vector3(Random.Range(0,300),
Random.Range(0,300),Random.Range(0,300));
other.transform.position = destination;
audio.Play();
}
}
Is the other collider at the root of the GameObject you want to move? $$anonymous$$aybe you're just moving the object with the collider but not the whole object. Use transform.parent or transform.root for that.
Your answer
Follow this Question
Related Questions
Go To new Scene Button! 1 Answer
Random Movement collision bug 3 Answers
OnTriggerEnter NullReferenceException 0 Answers
Randomly Initiate Cubes - Prevent Same Position 0 Answers
Deal Damage On Collision 3 Answers