- Home /
Collision too slow
I am creating an upscrolling space shooter (2D).
The problem is, my bullets go through the enemy and get destroyed like 2 centimeters behind the enemy.
I use this peace of code to detect if my bullet collided with an enemy:
function OnTriggerEnter (Target : Collider)
{
if (Target.tag == "Enemy")
{
Target.gameObject.SendMessage ("GoodDamage", 1.0, SendMessageOptions.DontRequireReceiver);
Destroy(gameObject);
}
}
I found answers saying to change collision detection, but that did not help. Everything "functional" works(calling "GoodDamage" & Destroy), just destroy is executed way too late. I'm especially wondering because frames/second are at least 250 and I am thinking there must bee a lot of frames where the bullet is right inside of the collider.
Answer by aldonaletto · Jul 09, 2011 at 03:34 AM
Try to reduce the bullet velocity just to check if it's really a delay problem. Another possibility: check if the model and the trigger are correctly aligned (sometimes we use the model childed to the trigger object, and they may get inadvertently misaligned)
O$$anonymous$$ I guess you already assumed that, but the collider for the bullets was behind the bullet (Z=0.15).
But while creating the prefab, I had to adjust the collider this way so it would be in the center of the gameObject. In playmode, the collider is centered perfectly with coordinates (0,0,0). Do you know why I have this coordinate difference between scene view and game view?
However, it works now, so thank you!
Oh also for information, my gameObject has the collider and a plane with texture as a child. Rotation and position of the gameObject are (0,0,0), scale is (1,1,1). The plane also has position (0,0,0), its rotated around Y 180° and scaled to 0.02.
(So I think its not a child problem...)
Strange thing this position shift: the settings defined in Scene view should be kept in Game view - I've never saw such a misalignment.
Haha yeah that's what I thought. Now that I know, I can work with it, no problem. But I'll make a new question, maybe someone knows whats happening...
Your answer
Follow this Question
Related Questions
How to maintain collision while moving the player? 2 Answers
Best practice for OnTriggerEnter detection 1 Answer
Collision update speed 0 Answers
Collision not working 3 Answers