- Home /
General Way To 'Widen' A Ray Cast?
Hello,
Is there a way to 'widen' a ray cast so its more liable to hit something. The Unity FPS tutorial on the weapons uses ray casting, but the ray cast is too accurate and pinpointed. So is it possible to widen the diameter or something around that area?
Reason I ask is because I have a turret that has a Slurp rotation, so when it tracks the enemy, it rotates with it slightly slower, or 'lagged'. And because it fires ray casts it tends to miss the target if the target turns in a slightly awkward way.
Thanks
Answer by Peter G · Dec 16, 2010 at 02:25 AM
Use a capsule cast. :)
Oh right okay, I only thought there was one type of ray cast, which was a line - Thanks Peter
How can I view the capsule cast in the editor to debug? Thanks
It's complicated since it doesn't really fit any standard gizmo. Personally, I would draw a sphere at the top and bottom points with the radius of the capsule, draw a line going the distance (unless it is infinity or your intention is to go beyond the boundaries of the scene. Then draw a ray). Then I would draw the sphere's again every 10 units or so. The problem is that requires quite a few draw calls, so it would be a performance killer. So 1, don't do it while optimizing, 2. Don't draw the increments closer than you have to.
Or just draw an icon. You won't get to see the volume as well, but it would be cheaper to render in the editor. Or, you could create a capsule that is "EditorOnly" and make it mostly transparent, then stretch it. Stretching it would be as simple as iterating through the verts and finding all of them that have a positive z value, then moving the z units forward.
Your answer
Follow this Question
Related Questions
Identifying Objects around me 3 Answers
Physics.CapsuleCast Help 1 Answer
Detect gameobjects via radius [PROBLEM] 1 Answer
How to make this script find distance inside radius? 1 Answer
Drawing capsule gizmos and keeping it with the object scale 2 Answers