• 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
-1
Question by Mark981 · Oct 23, 2012 at 05:40 PM · playerlaser

Line Renderer Collision Detection.

Hi,how can i make line renderer detects collisions on its way (Player) and when collision is detected then print("player detected")

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

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by greenshadow · May 12, 2013 at 06:56 AM

I think you're looking for something like this (C#)...

 RaycastHit hit;
 if (Physics.Raycast (lineStartPosition, lineEndPosition - lineStartPosition, out hit)) {
     switch(hit.transform.gameObject.tag)
     {
         case "Player":
             //Output message
             print("player detected");
         break;
     }
 }
Comment
Add comment · Show 2 · 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 Marks981 · May 12, 2013 at 06:11 PM 0
Share

Hey greenshadow,nice script,looks like it should work,but the script is wrong written and full of errors,i mean it dont works,can you please write script correctly?

avatar image greenshadow · May 12, 2013 at 06:56 PM 0
Share

$$anonymous$$ark, the script does work, I use it in a game I am making right now. The only thing is that "lineStartPosition" and "lineEndPosition" are Vector3 variables, but not variables that are defined in Unity namespace. You must replace them with your own Vector3s that you used to set your Line Renderer positions with.

$$anonymous$$aybe you can paste in a snippet of your current code for the Line Renderer, and I can show you from there.

avatar image
0

Answer by DaveA · Oct 23, 2012 at 06:03 PM

You may need to Raycast each line segment yourself. I hope there is a better answer

Comment
Add comment · Show 2 · 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 DaveA · Oct 23, 2012 at 08:52 PM 0
Share

Yes. You do Raycasting in scripts.

avatar image Mark981 · Oct 31, 2012 at 10:36 AM 0
Share

Anyway that was the worst answer ever.

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

12 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

Related Questions

Multiple Cars not working 1 Answer

Player destroys when he touches particle effect. 1 Answer

Raycast Destroys player. 1 Answer

Can somebody help me out with a jumpscare? (Like from the game "Slender") 1 Answer

How To Invoke RayCastAll? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges