Hi guys, I want to create a "Measure Gun" which fires a laser beam and then prints the distance between the gun point and the hit point. Heres my code
lineRenderer.enabled = true;
print("Distance = " + Vector3.Distance(transform.position, hit.point));
I attached this script with the gunPoint(gameobject from which laser is fired). But the problem here is that the other end of the laser beam gets snapped to certain points.. The gunPoint end is fine but the other end is not smooth...
It sounds like it's hitting something - do you have colliders that are invisible in the way?
Answer by Leon.S.Kennedy
Dec 27, 2012 at 10:10 AM
Oh ya, Thanks man, now i see i have an invisible rogue collider in the middle of the scene for no reason. dont know why i created in the first place.. After deleting it, the code works fine.. Also i got rid of hit.point and used hit.distance and now everything works as intended... Thank u very much man..
PS: I love your site www.unitygems.com... great work man..
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
To help users post good questions and use the site effectively we have posted a user guide. Please check it out.
Answers and Comments
10 People are following this question.
Need help fixing an error. Using raycast to mimic laster beam but no collider, Line Renderer, Raycast Collider.
Creating a Ray Gun
JS Script only work in Editor
Find a point at a distance from point on a line passing through two points
How do I make a collidable trail?