- Home /
Question by
Dreamer · Aug 31, 2011 at 03:35 AM ·
iphoneperformancecollision detection
Which way of doing 2D collision is faster?
I am doing a 2D game where enemies will shoot at my player. There are two ways to do collision of bullets:
Add colliders to bullets. Add rigidbody to player. Use OnCollision() way to do collision detection.
Use Vector3.Distance() to check every bullet's distance between player and bullets, if it is smaller than the preset value, then my player is hit.
The question is, which method will have better performance(less calculation)?
Comment
Answer by Waz · Aug 31, 2011 at 04:37 AM
2
or Vector2.sqr$$anonymous$$agnitude, or if you don't $$anonymous$$d a rectangular collision area:
if ($$anonymous$$athf.Abs(player.x-bullet.x) < range || $$anonymous$$athf.Abs(player.y-bullet.y) < range)
Hit();