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 N0tiC · Apr 01, 2011 at 01:01 AM · charactereffectweaponlaserbeam

Character lasergun?

Hi, I've been looking for a scrip that creates a laser from the characters gun. The game is in Top-down view and so i don't want a cursor or anything i just want a laser to go from the specific character point(Maybe an object that beams out the laser forward of the character?). However, I managed to make a laser with the class LineRenderer, but... I wasn't able to get it to follow the character while he was turning or even get it too look right since it's "glowing". I want a red and transparent straight line to go forward.

So to define exactly what i'm looking for i'll list it nicely:

  • A "laserbeam" (Red and transparent)

  • Coming from an object which is connected to the Player prefab (So it will follow while the character spinns)

  • stops when hitting a tree or another object

(- and can be turned off by a button click)

Nor should it continue forward for all eternity either, the line length should be editable. Could this be done by using some kind if sprite? How?

I know its much to ask for but i've been looking everywhere for this!:shock: Would be nice if this could be shared with the Unity3D community since all i've found is people who are looking for the exact same thing.

Ps: Scripting isn't my strong side so be nice & explain carefully!

Thanks, N0tiC!

alt text

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

1 Reply

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

Answer by Joshua · Apr 01, 2011 at 01:08 AM

I have a script where I'm doing something like this, but with several lines. Ingore the 'first line' part of the script, just read 'laser'. I should've edited but.. I'm lazy. ;)

var maxDistance : float = 2

function Start () { GetComponent(LineRenderer).useWorldSpace = true; }

function Update () { var laser = GetComponent(LineRenderer); var forward = transform.forward; var hit : RaycastHit;

 firstLine.SetPosition(0, transform.position);

 if(Physics.Raycast(transform.position, forward, hit) && Vector3.Distance(transform,position, hit) >= maxDistance)){
     laser.SetPosition(1, hit.point);

 }
 else{
     laser.SetPosition(1, transform.TransformDirection(0, 0, MaxDistance));
 }

}

Attach this to an empty gameobject which is childed to your gun. Make sure the z-axis is pointing 'character forward'.

Comment
Add comment · Show 8 · 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 N0tiC · Apr 01, 2011 at 01:34 AM 0
Share

I could definetly need help finding the laser material. It would be super if you could mail the material to me! Quick question: Why is the "laser" going towards the corner?

avatar image Joshua · Apr 01, 2011 at 01:46 AM 0
Share

right so i didn't alter the script because I'm lazy. where it says cueForward is where it is casting forward ( on the z axis). Alter this to change it.

avatar image N0tiC · Apr 01, 2011 at 01:54 AM 0
Share

I've tested what i know and i can't figure out how to do this. The object has the Line Renderer attached to it and its rendering alright. However, the object which i placed in center of the player suddenly moved to the corner and cannot be moved(Doesn't move visualy in the editor, just "in-game", going straight to where it's not suppose to go.).

And i'm pretty sure it's going from the object and hitting the player...

avatar image N0tiC · Apr 01, 2011 at 03:02 AM 0
Share

Hmm... This is not going anywhere... So i decided to make it very simple for now and get back to it later on(When there finaly is something to work with.). Anyhow... Now: http://xlentprojects.se/laser.jpg

avatar image Joshua · Apr 01, 2011 at 10:57 AM 0
Share

Do you have all this done on an empty game object, which is childed to your 'character' or gun with the z axis pointing player - forward? Also, please upvote/select the answer as correct if it's done :) it's nice for me + it will stop the bot from bumping your question for no reason

Show more comments

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

No one has followed this question yet.

Related Questions

Beam Weapon 1 Answer

Switching weapons animation with mecanim? 2 Answers

Animation system 1 Answer

How to draw beams? 2 Answers

How to do I create Laser light ? 2 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