- Home /
OnTrigger/Collision
I have a sphere which moves across a hall,and when it hits the player it reappears at it's initial position.The problem I am currently facing is that it only works if the player is moving,if he doesn't move the ball passes him .I am kinda new to unity and checked online but didn't find anything...
#pragma strict
private var Speed =0.35;
function Update () {
transform.position.z-=Speed;
if(transform.position.z<=-73){
transform.position = new Vector3(-150.71, 3.5, 35.98);
}
}
function OnTriggerEnter(other:Collider){
if(other.gameObject.name=="Player"){
transform.position = new Vector3(-150.71, 3.5, 35.98);
}
}
Does the Sphere have a rigidbody?
Try changing the Collision Detection type to Continuous or higher.
Answer by Avash · Dec 20, 2014 at 06:44 PM
You should use OnTriggerStay(). Always search for related pages from documentation. ;) http://docs.unity3d.com/ScriptReference/Collider.html http://docs.unity3d.com/ScriptReference/Collider.OnTriggerStay.html http://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html
Probably should've said it,but I tried OnTriggerStay and it doesn't do anything,the ball just passes the player
Use Stay() functions as little as possible. They update every frame an are very intensive on the system as a result.
Your answer
Follow this Question
Related Questions
OnTriggerExit() help 0 Answers
Can't click gameobject when over another trigger? 1 Answer
Changing current audio on trigger. 1 Answer
on trigger enter 1 Answer
OnTrigger events on multiple objects 1 Answer