Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 umutkarabuya44 · Oct 04, 2019 at 09:04 PM · linerendererlinedrawingcar game

Starting and Ending points of LineRenderer

Hello Everyone

Currently I'm working on a Demo which has similarities between a game https://modularmindset.itch.io/cardrawinggame-workingtitle.

I'm working on Unity3D and I draw lines with using LineRenderer sadly I'm not familiar with the concept so I have some problems.

When Each time player draws a line, I want to Instantiate wheels of the car in starting and ending points, How can I find Starting and Ending points of Line that I drew ?

Also after Instantiate how can I move the line with using tires ?

Thank you for even smallest answer.

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

Answer by lgarczyn · Oct 04, 2019 at 11:10 PM

This is a complex question, but not the part that you are thinking of.

To get the start and end positions, you just need to do this:

 Vector3 startPos = line.GetPosition(0);
 Vector3 endPos = line.GetPosition(line.positionCount - 1);

This will give you the local position (and world positions if they don't have parents) of the start and end point. This will crash if the line doesn't have points however. For this to work you need to disable useWorldSpace, or convert the result to local space.


Not if you want it to move, you will need to:

  • add a 2d rigidbody to your linerenderer

  • create a prefab for wheels, which will require a 2d circle collider, and a wheel joint. More details here. You will need to instantiate two of these prefabs, and attach them to your linerenderer, then set their ConnectedAnchor to startPos and endPos.

I suggest you try to do it in the editor before trying to code it.


This should give you a car, but the line won't collide with anything. For that, you will need to extract all the points of the lineRenderer, and add them to a PolygonCollider2d. Another option is to use the BakeMesh function from the LineRenderer and use this as the input for the polygon collider, but you'll need to convert it by hand.

There are other people who worked on this though, as you can find here:

https://answers.unity.com/questions/768997/how-can-i-add-a-collider-to-my-line-renderer-scrip.html

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 umutkarabuya44 · Oct 05, 2019 at 09:46 AM 0
Share

$$anonymous$$aybe I can do it in a different way, I can Instantiate wheels where I clicked mouse and Where I lift my finger it will be start and end position of the line ?.

avatar image lgarczyn umutkarabuya44 · Oct 05, 2019 at 03:20 PM 0
Share

Oh, yeah that works. Won't help for the next part though.

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

111 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

3d object outline shader 1 Answer

Draw path along Navmesh agent path 3 Answers

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

How to drag and drop lines in-game 1 Answer

Reflecting LineRenderer in water 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