- Home /
Collider colliding with itself
void OnCollisionEnter(Collision other) {
GameObject otherGameObject = other.gameObject;
if (otherGameObject == gameObject) {
Debug.LogError("WAT");
return;
}
if (otherGameObject == player && bDamageOnTouch) {
player.GetComponent<HealthController>().TakeDamage(damage);
bMoving = false;
timerMovement = timeToMove;
}
}
Wat
your debug is just checking that otherGameObject is a gameobject and it is. assigning other to another variable is not needed you can use other.whatever you would get from gameobject. a description of what is happening would also help posting the code and then expecting us to guess what is going on does not work.
No it's not, first at all this should be obviously as you can't check types by doing ("variable" == "type"). Second and even more obvious by the fact that gameObject is a reference to the GameObject owning the script. And the fact that gameObject starts with lowercase and GameObject not.
never the less you still have provided no assistance in helping you.
Any more information is superfluous, giving it will only attract people who don't know what is going on and try baseless assumptions which will delay the right answer.
Steps to reproduce: Create a box gameobject, give it a rigidbody, character controller and script a OnCollisionEnter, make the check. It will collide with itself, two times.
Saishy, this doesn't happen for me. There must be some other collider on the object or something else is going on :(
Answer by theAfrican · Jun 14, 2013 at 11:07 PM
are you trying to check for tag here?
if (otherGameObject == player)
what is player supposed to be? string or actual previously defined GameObject?
if its a tag then player should be a "string"
otherwise if player is a name of gameobject then you should compare using the .name property which is a string
if (otherGameObject == gameObject) { Debug.LogError("WAT"); return; }
Note return;
Your answer
Follow this Question
Related Questions
Not detecting collision on imported (DAE) objects? 1 Answer
collision detection not working? 1 Answer
Collision Enter one of the objects ? 1 Answer
Obstacle avoidance 1 Answer
Collision detection for sprite 1 Answer