- Home /
Raycast Shotgun
Hello, I'm quite new to Unity and have just finished the Survival Shooter tutorial, and was wondering whether it's possible to code the assault rifle into a shotgun spread Raycast, a circular one, this is the shooter part of the script, I have been trying but sadly have no succeeded, thank you if you can help!
void Shoot ()
{
timer = 0f;
gunAudio.Play ();
gunLight.enabled = true;
gunParticles.Stop ();
gunParticles.Play ();
gunLine.enabled = true;
gunLine.SetPosition (0, transform.position);
shootRay.origin = transform.position;
shootRay.direction = transform.forward;
if(Physics.Raycast (shootRay, out shootHit, range, shootableMask))
{
EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> ();
if(enemyHealth != null)
{
enemyHealth.TakeDamage (damagePerShot, shootHit.point);
}
gunLine.SetPosition (1, shootHit.point);
}
else
{
gunLine.SetPosition (1, shootRay.origin + shootRay.direction * range);
}
}
Thank you for any help you can offer!
Answer by connorwforman · Mar 01, 2018 at 04:11 PM
One thing that you could to is code multiple raycasts in a angled directions. Or, you could to prefab shooting but that will exponentially drop the FPS. This forum thread also might help.
https://forum.unity.com/threads/shotgun-raycast-problems.445329/
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
convert code C# to java.. 1 Answer
[C#] Raycast and raycasthit, destroy and instantiate gameobjects 1 Answer