- Home /
Question by
alexkaskasoli · Dec 17, 2013 at 12:11 AM ·
collisioncontrollercolliderhit
ControllerColliderHit, two objects, takes wrong one
I'm using this code to detect the collision between my player and "Cloud" gameObject. Funnily enough this code:
function OnControllerColliderHit(hit : ControllerColliderHit) {
if (hit.collider.gameObject.name == "Cloud") {
print(this.hit.collider.gameObject.name);
}
}
prints "Plane" in the debugger, which is not the behavior I'm looking for. Clearly the Collider must be detecting both the Plane and the Cloud (that cloud is sitting on a plane). How can I make sure that I'm taking the Collider with the Cloud and not the plane.
IE: make sure this hit.collider.transform = Vector3(0,0,0)
would affect the cloud and not the plane.
Comment
Best Answer
Answer by Meltdown · Dec 17, 2013 at 12:13 AM
Change your code from...
print(this.hit.collider.gameObject.name);
to
print(hit.collider.gameObject.name);
$$anonymous$$any thanks that indeed did it. Didn't even try that. Could you explain why this.hit != hit in this context? I thought 'this' would be unnecessary, but refer to the same hit?