Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by BigRedRedneck · May 31, 2018 at 05:29 AM · raycasttransformvector3line rendererinstatiate

How do I specify the origin and end points of the arc1 instantiated line?

The bolt material attached to arc1 spawns at the hand and goes the correct direction most of the time but sometimes it shoots randomly off into space and doesn't instantiate at the hand directly either. This is a script for a basic lightning bolt spell. Any other approaches for a lightning bolt would also be welcome as I am having issues with the line renderer.

using System.Collections; using System.Collections.Generic; using UnityEngine;

 public class LightningShooting : MonoBehaviour {
 
     //Debug.Log("1");
     public float range = 100f;
     public float timeBetweenBullets = 0.15f;
     public float effectsDisplayTime = 0.2f;
     public int lengthOfLineRenderer = 100;
     float timer;
     Ray shootRay;
     RaycastHit shootHit;
     int shootableMask;
     //[SerializeField]
     //public Animator arcAnim2;
     [SerializeField]
     private ParticleSystem sparksCast;
     [SerializeField]
     private LineRenderer arc1;
     [SerializeField]
     private AudioSource thunderAudio1;
     [SerializeField]
     private Light flashCast;
     [SerializeField]
     public int damagePerShot = 50;
     void Awake ()
     {
         
         shootableMask = LayerMask.GetMask("Shootable"); //layer of "Shootable" objects
         arc1.positionCount = 2;
     }
     void Update() 
     {
         timer += Time.deltaTime; // sets up the timer
         if (Input.GetKeyDown(KeyCode.Alpha2) && timer >= timeBetweenBullets) //if the fire key is pressed and the is timer is also less than timebetweenbullets
         {
             Shoot(); //defined below
         }
        
     }
 
     void Shoot () //what happens when shoot is called
     {
             timer = 0f; //reset timer
         Debug.Log("shoot");
         Instantiate<ParticleSystem> (sparksCast, gameObject.transform.position, Quaternion.identity); //emit fromt he particle system
         Instantiate<Light>(flashCast, gameObject.transform.position, Quaternion.identity); //light on player on
         Instantiate<AudioSource>(thunderAudio1, gameObject.transform.position, Quaternion.identity); // plays audio
         Instantiate<LineRenderer>(arc1, gameObject.transform.position, Quaternion.identity); // line for animation placheolder
         //Instantiate<Animator>(arcAnim2, gameObject.transform.position, Quaternion.identity);
 
         Vector3[] points = new Vector3[lengthOfLineRenderer];
         shootRay.origin = transform.position;     //moves ray for ray cast
         shootRay.direction = transform.forward;  // sets forward to positive z
 
         if (Physics.Raycast (shootRay, out shootHit, range, shootableMask)) //if you hit something in the layer "Shootable"
             {
                 EnemyHealth enemyHealth = shootHit.collider.GetComponent<EnemyHealth>(); //look for script enemyhealth
                 
                 if(enemyHealth != null) //if the object isn't a player
                 {
                     enemyHealth.TakeDamage(damagePerShot, shootHit.point);  //take damage, create a point to plac eblood splatter etc.
                 }
 
                 arc1.SetPosition(1, shootHit.point); //draws line for line renderer
             }
             
             else //if not on the shootable layer...
             {
                 arc1.SetPosition(1, shootRay.origin + shootRay.direction * range); // set the end point to extent of range
             }
     }
 }






Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

203 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

I need help with the location of instatiated objects on the scene and correct interaction with this 0 Answers

Whats the difference between Vector3.zero and Vector3(0,0,0)? 3 Answers

Can't move instantiated object. 1 Answer

Can’t keep the position 0 Answers

How can I make this translation smoother? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges