• 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
Question by LocalNoob · May 24, 2017 at 10:29 AM · 2droads

[SOLVED, kinda]How to go about creating smoothly turning roads?

In 2D. I would like to make a rail(for a train game) sprite in w$$anonymous$$ch you can manipulate the end points to get a smoothly turning railroad. Just give me an idea on what's the best way to go about it. Thanks.

http://catlikecoding.com/unity/tutorials/curves-and-splines/
So I followed t$$anonymous$$s tutorial got a bezier(smooth) curve w$$anonymous$$ch I could manipulate and add up more to it and then used two line renderers(w$$anonymous$$ch follow their spline) to draw the sides of my rails (w$$anonymous$$ch always stayed at the same distance, making it all work) and then the idea was to depending on the distace of the rail curve to create many new line renderers(in between my two main long curves) every n units but I didnt complete the second part of the idea cause it was too much effort for a small project.

Comment
GoldenProlix
meltahawy

People who like this

2 Show 1
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 ShadyProductions · May 24, 2017 at 10:32 AM 0
Share

I believe the best way to go is to just create railroad turn sprites/textures to each direction, there is not really a good way to edit 2D sprites/textures during runtime.

2 Replies

· Add your reply
  • Sort: 
avatar image

Answer by meltahawy · Jun 01, 2017 at 01:45 PM

@LocalNoob

Look into Unity spline solutions. I believe t$$anonymous$$s asset might be of use to you: https://www.assetstore.unity3d.com/en/#!/content/7038 (Curvy - $50)

Here is another cheaper one to check out: https://www.assetstore.unity3d.com/en/#!/content/2506 (Simple Waypoint System - $15)

T$$anonymous$$s tutorial is also very helpful if you would like to code a script on your own: http://catlikecoding.com/unity/tutorials/curves-and-splines/ (it is in 3D though)

Comment
JonPQ
LocalNoob
Cornelis-de-Jager

People who like this

3 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 LocalNoob · Jun 13, 2017 at 09:45 PM 0
Share

Thanks for the answer. I actually found the catlike's tutorial recently and am following it through right now. I think it is the solution to my problem

avatar image

Answer by GoldenProlix · May 25, 2017 at 07:07 AM

If you don't need it to be pin-point accurate (like just an animation) I would simply make a few different images in Photoshop and make an array containing with each image and then do somet$$anonymous$$ng like t$$anonymous$$s.

 Update(){
 timer += Time.DeltaTime
 if(timer > animateFrameTime && isAnimating)
     {
      timer = 0;
      showNextImageInArray();
      if(imageShowing == imageToStopAt)
              isAnimating = false;
     }
 }

T$$anonymous$$s way you can choose the time it takes for each image to show and you can create in-between images so it looks like a smooth transition. : )

Comment
LocalNoob

People who like this

1 Show 3 · 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 LocalNoob · May 28, 2017 at 03:29 PM 0
Share

But how to go about making turns? This approach will work for straight rails but not really for smooth turns

avatar image GoldenProlix LocalNoob · May 29, 2017 at 10:17 AM 0
Share

I'm not 100% on the specifics of your game but say you were able to move the endpoints every 10 degrees. You would have to create an image for each of those 10 degrees (and if you wanted it to be extra smooth an image for every 5deg, 2deg...and so on) when the user is moving the endpoints you loop through the images to show the correct one. If you needed to have endpoints on both side of the rail road, all you would have to do is rotate the image until the start aligns and then offset your image array by that many degrees (if you rotate the image 90 degrees and your image interval was 5deg, then offset the array by 90/5 or 18).

avatar image LocalNoob GoldenProlix · May 29, 2017 at 08:05 PM 0
Share

Okay. Now I get what you mean. I will try this approach out. Thanks

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Assets/Scripts/PlayerController.cs(32,49): error CS0126: An object of a type convertible to `float' is required for the return statement 1 Answer

2D Animation does not start 1 Answer

Calculating the Angle between two vectors 2 Answers

PSD Importer creates unslicable mesh, animation moves up 0 Answers

Delete first object of the same type in a list? C# 1 Answer


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