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 SouzaDev · Aug 07, 2014 at 02:15 PM · c#2d

Unity minecart 2d idea

Hello everyone. I am new to Unity and I wonder if someone could help me with my game 2D any idea how to do. The idea is to make the cart can walk between independent rails as in this video: https://www.youtube.com/watch?v=Gt1qf2SrkME

I've heard in ITween but I can only make it stand following a path

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 robertbu · Aug 07, 2014 at 04:16 PM

Let's assume iTween, because if we open it up, this question has a lot of possible implementations and becomes a design question better posted on Unity Forums.

  • Define two parallel paths in iTween. There is a free visual path editor for iTween you can get here, but you can also define your own array of Vector3s or array of Transforms.

  • Use iTween.PutOnPath() and iTween.PointOnPath() for placing and moving objects on the path (not the orienttopath for things like MoveTo()).

  • PutOnPath() and PointOnPath() use a fraction between 0.0 and 1.0 where 0.0 is the beginning of the path and 1.0 is the end of the path. If you get the current position and then a position slightly ahead of the current position, you can produce and direction and from that an angle. This gives you the needed information to angle your cart and to calculate the physics (go faster downhill and slower uphill).

  • To switch paths, use the same fraction but replace the array used. Here is an answer for someone doing that with iTween.

  • In the link just provided, you will also see code that increments the fraction from 0.0 to 1.0 and therefore move the object along the path.

  • The physics of swapping I'd handle by moving an empty game object along the path with the visible object a child. When switching paths, the empty game object moves immediately, but the physical game object lags and is Lerp()ed or MovedToward()ed using Trandform.localPosition. Here is a similar question to give you an idea.

Comment
Add comment · Show 7 · 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 SouzaDev · Aug 07, 2014 at 06:48 PM 0
Share

I understand the idea and am very grateful for your help. I'm following this example but I have a doubt. During the jump the car can find the current path or another path. How can I do understand that the car jumped an path and found another path?

avatar image robertbu · Aug 07, 2014 at 09:29 PM 0
Share

Using PutOnPath(), your position is specified by a fraction. So if you specified 0.5 as the fraction, the object would be at the 1/2 point on the path. As I mentioned, I would structure this so that an empty game object is walking along the path with the visible object as a child. When the user changes to another path, the empty game object immediately changes to the new path at the same fraction, but by modifying the the localPositon in the visible child, the visible object initially doesn't change position but is Lerp()ed to the same position as the empty game object.

Imagine the visible object connected to the empty game object by a spring. When the cart switches paths, the empty game object is immediately placed on the new path stretching out the spring. The visible object catches up with the empty game object as the spring contracts. There is no finding involved.

There is one issue with the way iTween handles paths that may require you to be extra careful. You want a one-to-one mapping of positions between the two paths, in terms of number of vertices, and you want the 'x' position of each vertex to match up as well. So if you need to curve the upper path up for a jump, you might place 'unnecessary' vertices in the lower path to keep things matched up. This would not be true if you went with a more sophisticated spline package as are available (for $) in the Asset Store.

avatar image SouzaDev · Aug 07, 2014 at 11:49 PM 0
Share

Sorry my little understanding of Unity. I managed to make an example of the first link. I made 3 paths with iTweenPath and they change paths by pressing the buttons! But I want to make irregular paths , broken roads, making the cart "jump" between the span or jump to another path alt text

untitled-1.png (41.2 kB)
avatar image SouzaDev · Aug 07, 2014 at 11:58 PM 0
Share

I thought about putting in some places the polygoncollider In These three paths. The cart will run on These colliders and- When not collide, the card will fall. When you jump and find the collider, will go que way. Do it this way is right?

avatar image robertbu · Aug 08, 2014 at 12:32 AM 0
Share

Physics and iTween are very different approaches. And there is an a middle choice of using colliders and a character controller of some sort. Note I was looking specifically at what they do in the video. It would be easy to extend the path solution so that there were breaks in the path (and more paths), but you would not have random platforms like are in your drawing. This is devolving into a design question. $$anonymous$$aybe you want to get a real clear vision of what you want (and how it is different than the video), and then ask a design question on Unity Forums.

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

2 People are following this question.

avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Unity Sprites Overlapping, slightly see-through (2D game) 2 Answers

How do I use MoveTowards in 2d? 1 Answer

How to update assigned vector variable in unity C# 1 Answer

Creating 2D art in a 3D world 3 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