- Home /
Colliders vs RayCast (automatic crosshair aiming in an FPS game)
Colliders vs RayCast
I have to implements automatic crosshair aiming in my FPS game. What is the best (performing on iPhone) solution for that?
I can see two options here:
1: Using Triggers:
Ex: Adding an additional collider to the player object in shape of a long stick, potentially long sphere) and a rigid body marked as kinematic Detecting OnTriggerEnter/Exit between player and enemy colliders. After that use a linecast and if there are no objects on the way moving crosshair based on enemy position.
2: Using RayCasting:
Ex. Use couple (at least three) raycasts in a direction coming from camera, detect object on their way using Physics.Raycast Once enemy has been detected move crosshair based on its position.
So, what is the most expensive operation? Using rigidbody with OnTriggerEnter/Leave handling with one LineCast or 3 raycasts (with additional layer)?
Thanks
Answer by Lucas Meijer 1 · Dec 11, 2009 at 07:52 PM
If your goal is to aim your crosshair at the closest enemy, if that guy is close enough, you could solve it much simpler, by using Camera.WorldSpaceToScreenSpace() and getting the screencoordinates of this guy. If it's close enough to the middle of your screen, you can rotate the camera/crosshair more towards the guy.
Doing triggers and raycasts seems like very performance heavy operations that don't actually get you want you want.
fair enough, but I am wondering the same question but without any screen interaction, so what is actually faster? raycast or trigger?
Your answer
Follow this Question
Related Questions
Can I stop a lerp completely when it gets to 20% of its original value? 3 Answers
How to do iPhone Optimization with materials, textures and callbacks? 1 Answer
iPhone Optimization - using 1024x1024 textures for background 0 Answers
What is the expected behaviour of Dynamic Batching? 2 Answers
do static variables slow down framerates in iphone 2 Answers