- Home /
Collider not triggered when change posision
I was doing the 1st Lab of Walker's Boys training session.
What I am trying to do is randomize 3 cubes in front of camera without collided with other by OnTrigger/OnCollision functions
The problem is the event does not trigger if those cubes didn't move after instantiate or move(It's work just fine when a cube fall on another cube)
Is that how it support to be, or I missed something? Here the code:
function move(){
var position :Vector3;
position.z= 9;
position.x= Random.Range(-0.7,1.7);
position.y= Random.Range(13.2,15.2);
this.transform.position=position;
}
function OnCollisionStay(other:Collision){
Debug.Log("Triggered");
this.move();
}
Please give me some direction, I dont have any idea where to start looking for.
Answer by ThePunisher · Oct 05, 2012 at 04:50 PM
Check out the doc:
http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionStay.html?from=Collision
It says you might want to take out the "other:Collision" parameter from the OnCollisionStay method unless you are actually using it.
Now to address the actual problem. As I understand, if your cubes are able to trigger each others colliders (which makes sense), but something else is not then that GameObject is missing a collider and a rigidbody component.
Also, know that the OnCollisionStay is called for every frame that the objects are colliding, if you only want to know when the initial collision happens then you might want to use OnCollisionEnter (or OnTriggerEnter)
http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionEnter.html?from=Collision
Thanks, it's work after I added rigidbody (without gravity and freeze everything). $$anonymous$$y cubes still have the collider since the start, but maybe it's just not work in this situation.
Your answer
Follow this Question
Related Questions
Unity 2D - MoveTowards position not updating, not recgonizing new position 1 Answer
GameObject change Position after game started 1 Answer
how to I zero out a parented child's position in X,Y,Z on collision? 1 Answer
Keep instantiated GameObject's position while parenting it to another GameObject 3 Answers