Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by robotcousin · Jan 31, 2013 at 03:27 AM · collisionrandomspawnturretlaser

Help moving turret shoot lasers

Hi all,

My situation is that I have a turret moving back and forth across the north wall in a square room. I'd like it to shoot out a short laser beam straight out every so often, maybe every 2-3 seconds, from wherever it is at the time. I've created the laser shot prefab (it's a LineRenderer) and used a script online that makes the laser move forward immediately at runtime, but the turret moves away from it (and never de-spawns). How can I:

  • Ensure that the laser will spawn at the exact spot on my turret? I assume I attach an empty and invisible game object to where I want it to spawn (which will also move with the turrent), and use that, right? That I think I have correct.

  • Make sure the laser always moves in whatever way the turret is facing? I don't plan on having the turrets turning DURING the game, but I'd like to be able to take the turret (and laser beam shot) I've made, duplicate it, move it to another wall, facing a different direction, and still have the laser move outwards from it.

  • Kill off the laser either when it hits the opposite wall, or flies far enough out of bounds?

Comment
Add comment · Show 2
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
avatar image Tim-A · Jan 31, 2013 at 01:21 PM 0
Share

Have you got the laser to shoot every 2-3 seconds?

avatar image robotcousin · Jan 31, 2013 at 01:24 PM 0
Share

No, haven't gotten that far yet.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Tim-A · Jan 31, 2013 at 01:38 PM

To shoot every 2-3 seconds you would use Time.time.

     var spawnPos : Transform;
 var laser : LineRenderer;
 private var spawnTime : float = 2;
 
 function Start () {
 
 spawnTime = Time.time + 2;
 
 }
 
 function Update () {
     
     if(Time.time > spawnTime){
         spawnTime = Time.time + 2;
          var clone : LineRenderer;
         clone = Instantiate(laser, spawnPos.position, transform.rotation);
             
 }
 }

I'm not sure if the code works. I haven't tested it yet, but if you come up with any errors ask me. Set spawnPos to the empty game object you want it to spawn from and Laser to you're laser line.

Comment
Add comment · Share
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
avatar image
0

Answer by iwaldrop · Jan 31, 2013 at 05:00 AM

  1. Create a reference Transform as a child of you laser turret.

  2. Spawn your laser shot using the reference's position and rotation.

  3. Make sure the laser has a collider and

  4. Destroy the laser when it hits something (after doing damage if it hits something you want to damage).

Comment
Add comment · Show 1 · Share
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
avatar image robotcousin · Jan 31, 2013 at 12:44 PM 0
Share

Thanks, greatly appreciated. Now I just need to figure out the specifics of how to do what it is you posted. By 'reference transform', do you mean just an empty game object? Or a script? What would be in that script, if that's what I need to put in?

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

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

Collision, but then only affect ONE of the gameObjects? 2 Answers

Respawn random objects 1 Answer

Spawning objects in infinite scroller game 0 Answers

Trigger Spawning? 1 Answer

Random Movement collision bug 3 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