- Home /
Multi-Pierce Raycast Shot.
What I'm asking about is how to make a non-projectile shot pierce through multiple objects. Preferably in C#. However, I also am looking for a way to govern the pierce, due to the long range of the weapon I'm setting this on, infinite pierce would be far too powerful.
I have a basic shooting script (based highly off of the Intro to Shooter Mechanics tutorial example, with small, mostly immaterial changes), and I am trying to extend it a bit by using this. But, I am fine with just dropping the one I'm currently using, and writing a new one if needed.
Answer by doublemax · Jan 18, 2017 at 09:24 PM
Physics.RaycastAll: https://docs.unity3d.com/550/Documentation/ScriptReference/Physics.RaycastAll.html
Answer by Seik_Luceid · Nov 05, 2019 at 01:45 PM
float maxPierceDistance = 100f;
Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit blockHit;
if(Physics.Raycast(ray, out blockHit, maxPierceDistance, LayerMask.GetMask("Cover")))
{
maxPierceDistance = blockHit.distance;
}
RaycastHit[] hit = Physics.RaycastAll(ray, maxPierceDistance, LayerMask.GetMask("Enemy"));
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Physics2D.Raycasting questions 0 Answers
Multiple Cars not working 1 Answer
How to Calling function in JS from C# 1 Answer
Raycast2D is inconsistent 0 Answers