- Home /
Objects Touching?
I'm currently struggling with checking if two objects are touching but didn't collide this is because for a certain sword swing I am moving the position of the sword forward rapidly meaning it doesn't actual collide with the enemy but has it's position in the enemy so that they are touching. when i move the character the enemy dies but not when both are stationary and the player attacks?
How can I check that two objects are touching but didn't collide?
The code I'm currently using, it works when the enemy or the player is moving and the sword is swung but if both the enemy and player are standing still the script doesn't destroy the object
here is the code
function OnCollisionStay (collision : Collision) {
if (collision.gameObject.tag == "RedEnemy"){
Destroy(collision.gameObject);
}
}
EDIT I noticed that a lot of people view this question with presumably the same problem? If that is the case I would like to inform the community that I ended up using a system where I got the distance between the players and enemies to figure out weather they were touching or not as this system is much more reliable than Unity Collision system (which has its place to work). I have since stopped working not his project so can provide no other feedback to it.
So you say that collision works when you move your character? $$anonymous$$aybe you should change collision to trigger (it can be checked on colliders) and if OnTriggerEnter doesn't work, maybe OnTriggerStay/OnCollisionStay? But then you'd need to make some checks so that the enemy dies only once
I tried trigger enter >.< didn't work am going to experiment with CollisionStay
can you post your code? It's going to be easier to check what's wrong
Answer by Montraydavis · Oct 30, 2012 at 04:32 PM
if (collision.gameObject.tag == "RedEnemy"){
Destroy(collision.gameObject);
}
should be. . . .
if (collision.collider.tag == "RedEnemy"){
Destroy(collision.gameObject);
}
You are very welcome! I am glad that this has solved your issue :)
Thanks for supporting Unity3D
Your answer
Follow this Question
Related Questions
how to make a script when u collide with an object it disappears 3 Answers
collision with objects, physics 1 Answer
2D game object trigger 1 Answer
Detecting another object collision from another object script (2D) 0 Answers
How can I make a sound deploy after colliding with a certain object (or terrain)? 1 Answer