- Home /
Particle Instantiation problem.
So, I have this script which allows me to shoot using raycast.. I have the script attached to barrel of my gun.when i went about to add spread factor, using debugging, I can see my ray spreading but particles and bullet holes instantiate only at center of the screen. They are not instantiating according to raycast hit points. Anyone have any idea how to fix this?.
I want this script to cast ray from center only to spread hits around crosshair more precisely. So, i want the var ray as it is, but with the spread effecting particles and bullet holes too.Thanks in Advance :)
function CastRay()
{
var Hit : RaycastHit;
var direction : Vector3 = transform.forward;
direction.x += Random.Range(-spreadFactor, spreadFactor);
direction.y += Random.Range(-spreadFactor, spreadFactor);
direction.z += Random.Range(-spreadFactor, spreadFactor);
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
Debug.DrawRay(transform.position, direction * Range, Color.green);
if (Physics.Raycast (ray, Hit, Range))
{ audio.PlayOneShot(audioShot);
if(Hit.collider.tag == "Enemy")
{
var Spaclone = Instantiate(SparksEffect, Hit.point, Quaternion.LookRotation(Hit.normal));
Destroy(Spaclone.gameObject, 0.5); Spaclone.transform.parent = Hit.transform;
var SparksClone = Instantiate(SparksEffect, Hit.point, Quaternion.LookRotation(Hit.normal));
Destroy(SparksClone.gameObject, 0.5); SparksClone.transform.parent = Hit.transform;
}
Hit.collider.gameObject.SendMessage("Damage");
Your answer
Follow this Question
Related Questions
Instantiate diffent particle for different object 1 Answer
Why cant this work 1 Answer
raycast from an empty gameobject? 1 Answer
different particle on enemy second hit 0 Answers
Unity Raycast Script, Help! 1 Answer