• 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 /
avatar image
0
Question by 1337GameDev · Apr 05, 2013 at 04:07 PM · collisionmobilelinerenderersplitlaser

laser simulation with line render and colliders

I am creating a laser that will be used as a projectile.

My current algorithm is this: 1. I have a projectile prefab that renders a line through 2 points as my laser. 2. When it is "fired" out of gun, the laser front position only moves forward, until it's length exceeds the laser size i want, then i use a bool to say it has left barrel 3. Then i move the front and back positions forward 4. when i raycast to the next position of the front, and it collides with something, i stop the front and keep moving the back. (i apply damage here) 5. I raycast between the front and back of the laser beam to determine if a ship intersects it, for which i split the laser and make another copy and set each laser front/backs to look as if it was one laser stream split in two

My problem: This only works if the ship doesn't move AFTER my laser does (or the ship moves within range of my laser's next move amount and the laser can stop).

If the ship moves after my laser does this raycast, the ship will be within the laser beam, and the beam splits (which is not wanted as this will happen over and over). I want my laser front to move backwards to simulate the laser colliding with the ship.

I could store which ship stops the laser initially, and next frame raycast backwards, and if its the same, move the front backwards, but if the ship never intersects the front and just hits the laser front from the side, the splitting problem happens.

How do I accommodate for this case? What is a good and efficient way to handle this laser movement and such that would also be acceptable for mobile?

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

11 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

Related Questions

Laser using line renderer 1 Answer

Test line renderer collision? 1 Answer

How to check of a line renderer collides with ground ? 1 Answer

Maximum Fixed Timestep Allowed on an iPhone/Android 0 Answers

Colliders vs Callbacks: Which is better for performance in my case? 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