- Home /
Not Quite Sure How OnCollision... Works
I've been having trouble with this for a long, long time. I can't seem to get this code to work, no matter what I try.
var player : GameObject;
var apexHeight : int;
var normalHeight : int;
var onTop : boolean;
function Start(){
player = GameObject.Find("Player");
}
function OnCollisionStay (collisionInfo : Collision) {
if(collisionInfo == Collision.player)
rigidbody.AddForce(Vector3.up * 50);
}
Answer by Wolfram · Jun 19, 2012 at 12:38 AM
Replace your if with:
if(collisionInfo.gameObject == player){
Do you know how the equality is calculated ? I usually don't trust it and check the GetInstanceID, but maybe that's actually what it does already.
Thanks! I've had this problem forever and somehow never tried that... :/
@Berenger - not sure how pointers/references are handled here, especially not in JavaScript/UnityScript, which I don't use. But it should just be a comparison of the two references - if they point to the same object, it's "true", so there should be no difference to using GetInstanceID.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Destroy on collision 3 Answers
How to destroy bullet on collision! 2 Answers
Sphere detection system 2 Answers