So after searching around, I either found irrelevant topics or script in Java, but I need one in C#, I’m having problems making particles emit when a line renderer touches the object with a capsule collider, I am using everything learned from the laser live training session.
I just can’t seem to figure out how to make particles emit when the line renderer hits the collision box. I know it has to do with oncollision enter, right?
A line renderer by itself will not fire collision or trigger events. You need to have a second collider touch the object with the capsule collider to detect a collision. Then you can play the particle system.
I know what to use but I don’t know how to write the needed portion for this event. Can I add a collider to the line renderer if it has a distance of 100? Here’s the code I’m currently using, the Gameobject. instantiate near the end is what I was trying to use to make the particle effect instantiate, but I’m not sure how to write it.
IEnumerator FireLazer() // IEnumerator is a coroutine return type. Continually fires while holding down the button
{
line.enabled = true;
audio.Play ();
while(Input.GetButton("Fire1")) //get button down only fires once. Get button fires when held down
{
Ray ray = new Ray(transform.position, transform.forward); //Transforms.position comes from the position of the object, transform .forward fires straight. or direction thing is facing
RaycastHit hit;
//audio.Play();
line.SetPosition(0, ray.origin);
if(Physics.Raycast(ray, out hit, 100))
{
line.SetPosition (1, hit.point);
if(hit.rigidbody)
{
hit.rigidbody.AddForceAtPosition(transform.forward * Pew, hit.point);
//GameObject = Instantiate(GameObject, new Vector3(0f, j, radius ), Quaternion.identity);
}
//if (Input.GetButtonDown("Fire1"))
//audio.Play();
}
else
line.SetPosition (1,ray.GetPoint(100)); // get at 100 units forward or from 100 units forward or the end
yield return null;
To solve my own problem, I was able to use hit.point, if anyone else for some reason needs help, here it is!
just replace Col with your particle prefab.
IEnumerator FireLazer() // IEnumerator is a coroutine return type. Continually fires while holding down the button
{
line.enabled = true;
audio.Play ();
while(Input.GetButton("Fire1")) //get button down only fires once. Get button fires when held down
{
Ray ray = new Ray(transform.position, transform.forward); //Transforms.position comes from the position of the object, transform .forward fires straight. or direction thing is facing
RaycastHit hit;
//audio.Play();
line.SetPosition(0, ray.origin);
if(Physics.Raycast(ray, out hit, 100))
{
line.SetPosition (1, hit.point);
if(hit.rigidbody)
{
hit.rigidbody.AddForceAtPosition(transform.forward * Pew, hit.point);
Instantiate(Col, hit.point, Quaternion.identity);
}
//if (Input.GetButtonDown("Fire1"))
//audio.Play();
}
else
line.SetPosition (1,ray.GetPoint(100)); // get at 100 units forward or from 100 units forward or the end
yield return null;
}
line.enabled = false;
audio.Stop();
}
}
PLEASE TELL ME WHERE DO YOU ATTACH Your PARTICLE SYSTEM TO THE BEAR OR TO THE GAMEOBJECT OF LASER WHAT IS particle prefab
there is no particle prefab in particle system