Тёмный

Making a Spline Train Using Rigidbodies to Move | Unity C# 

Paridot
Подписаться 1,3 тыс.
Просмотров 18 тыс.
50% 1

Instead of animating a train along a spline, I wanted it to move using physical forces instead. I'll show you how I accomplished that in this video!
If you'd like to support me making these videos, this is a great place to do so :)
ko-fi.com/paridot
The method for coupling carts done here has been vastly improved in a new video. Go check it out! • Using Configurable Joi...
0:00 - Intro
0:58 - Spline Package
1:38 - Spline Component
2:24 - Force Object on Path
5:00 - Modelling Carts and Links
5:53 - Outro
Reddit post mentioned: / spline_based_rigidbody...
GitHub Repository:
github.com/Paridot/YT_Physics...
Join our Discord Server!
/ discord
Wishlist our game RUIN!
store.steampowered.com/app/25...

Опубликовано:

 

1 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 33   
@er6n10
@er6n10 Месяц назад
Great stuff! Saved me from a headache I have been having while using the SplineAnimator...
@paridotgames
@paridotgames Год назад
*UPDATE* : I would advise not coupling the carts the way I did in this video - rigidbodies and collisions happen to be very unreliable joints. Instead, use actual joints! I made a new video specifically going over this: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-F2CWDjjyadM.html
@TrentSterling
@TrentSterling Год назад
Hey I came across that same reddit thread before I found this video. Thank you for documenting how this works with example code! I plan to combine this with a hinge joint that has break force, for fun reasons
@paridotgames
@paridotgames Год назад
Glad to hear it has been a bit helpful! I haven't tried hinges yet but when I revisit this I think it will be the next thing I do. The way I set up the collider links on this project are a bit unreliable haha. Let me know if you get them working! I'd like to hear how it goes.
@falconelsu9798
@falconelsu9798 Год назад
That's awesome
@jeakdataje
@jeakdataje Год назад
we can't see the entire code in the video, please share the code.
@j.j.maverick9252
@j.j.maverick9252 Год назад
awesome work! Thanks for the walk through of your approach. I’ve done a number of spline based projects and often run into problems converting the time 0…1 into a velocity that is constant on different length splines (calculating the length is mostly an iterative approximation). I’m going to dig through your example and that reddit thread to see if there’s a better way.
@paridotgames
@paridotgames Год назад
Hopefully it's helpful! Sounds like you're animating the transform based on a lerp between the start and the end of the spline? If that's true, my example is pretty much throwing that whole method out of the window lol. I just find the nearest point on the spline, snap the transform to it and make it face the direction of the tangent of the current point, then reapply the velocity onto the rigid body from the last frame. Very "hacky" solution but it allows for the application of physical forces while still following the spline. If I'm understanding your problem properly, you could implement my solution here, but just set the velocity to a constant value - this will stay the same no matter the length of the spline.
@j.j.maverick9252
@j.j.maverick9252 Год назад
@@paridotgames superb, thanks for your suggestions. Your demo looks super-cool!
@ilikecakeandbiscuits
@ilikecakeandbiscuits Год назад
Great tutorial. I'm having a problem where the train follows the track in the centre of the room and not where the spline is. Have a feeling it's due to the global vs local position but not sure how to get it to snap to the track!
@Hazzel31337
@Hazzel31337 Год назад
nice tuuut tuuut, nice "tutorial" great explanation
@paridotgames
@paridotgames Год назад
Thank you! 😃
@RiFTRiSiNG
@RiFTRiSiNG Год назад
Hi, great tutorial, perfect for what I'm trying to do. I don't understand how you have attached the train cars, using a joint or in script? It was not shown in the video. Also, what can I add to the script to make the spline work if it is not globally centered. Thank you
@paridotgames
@paridotgames Год назад
It was probably easy to miss but I did cover it in the video - I essentially added collider hooks on the front and back of each cart, then interlinked them such that they'd act like a chain pulling each other along. This proved to be very bug ridden and slow though and I have since re-implemented it using configurable joints instead. I plan to make a follow up video for that next, so if you're having trouble figuring it out yourself stay tuned for that :) For the spline global position problem, I have not spent the time working on that so I couldn't explicitly help you there, but I would think adding the current global position of the spline to each point you're accessing as an offset would be a good place to start. Hopefully that helps and good luck!
@RiFTRiSiNG
@RiFTRiSiNG Год назад
@@paridotgames Thank you!
@boywithbrain7556
@boywithbrain7556 3 месяца назад
How did you aligh your bodies to the spline? cause mine always work on the spline with an offset
@NDBucket
@NDBucket Год назад
GetNearestPoint returning a local space vector instead of global really screwed me up too (my transform was at 0.9, 0 ,0 so it was just slightly off), glad I'm not the only one!
@paridotgames
@paridotgames Год назад
That was quite the frustrating realization lol
@Hozgen
@Hozgen 9 месяцев назад
i wanna carry the gameobject conntected to spline container but the locals will not :(
@crafty_dan1362
@crafty_dan1362 Год назад
Would anyone have any ideas on how to create splits in the track that the train can choose between. I know you can can create "branches" with the spline tool but how would the play choose between which path to take? Thanks for your help!
@USSR-Lenin-Stalin-Forever
@USSR-Lenin-Stalin-Forever 9 месяцев назад
ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-ipKeYqYB4oY.htmlsi=Lm2nZLCvvE3gYHW6
@tomtintenfisch8029
@tomtintenfisch8029 Год назад
do you know where to find good documentation on the spline tool? i cant find anything good
@paridotgames
@paridotgames Год назад
Unity supports the spline package so they have a manual and API docs on their website docs.unity3d.com/Packages/com.unity.splines@2.0/manual/ It's definitely helpful, but for me I found it much more useful to just open up the example projects that come with the package and step through the code to see exactly how they use the API. I was able to more easily envision what I needed to do with a bigger picture understanding of how the code works together.
@tomtintenfisch8029
@tomtintenfisch8029 Год назад
@@paridotgames thank you, subbed
@paulandersson3315
@paulandersson3315 Год назад
What Spline Addon do you use?
@paridotgames
@paridotgames Год назад
I'm using the standard Unity supported spline package: docs.unity3d.com/Packages/com.unity.splines@1.0/manual/index.html You can install it from the Unity package manager
@paulandersson3315
@paulandersson3315 Год назад
@@paridotgames thx
@MegaXDBrasil
@MegaXDBrasil 10 месяцев назад
Wtf very big
@emi574
@emi574 5 месяцев назад
Make bogies rotate instead of whole locomotive
@USSR-Lenin-Stalin-Forever
@USSR-Lenin-Stalin-Forever 9 месяцев назад
Matrix4x4 localToWorldMatrix = track.transform.localToWorldMatrix; Matrix4x4 worldToLocalMatrix = track.transform.worldToLocalMatrix; float distance = SplineUtility.GetNearestPoint(track.Splines[indexSpline], worldToLocalMatrix.MultiplyPoint(transform.position), out Unity.Mathematics.float3 nearest, out float t, 2); nextWagon.transform.position = localToWorldMatrix.MultiplyPoint(nearest);
@Hozgen
@Hozgen 9 месяцев назад
Is it for global? 🤔
@Hozgen
@Hozgen 9 месяцев назад
thats fine worked :D
@laytonvicars4606
@laytonvicars4606 3 месяца назад
Thank you very much!
Далее
SPLINES en Unity
11:41
Просмотров 4,3 тыс.
치토스로 체감되는 요즘 물가
00:16
Просмотров 3,1 млн
Making another pickproof lock (but better)
15:14
Просмотров 2,8 млн
How to Plan a Good Railway Station
10:03
Просмотров 42 тыс.
Unreal engine train physics its possible!!!!
0:55
Просмотров 14 тыс.
Why I Still Use Unity
7:28
Просмотров 9 тыс.
How do non-euclidean games work? | Bitwise
14:19
Просмотров 2,4 млн
I Made A Difficult Game About Climbing
15:04
Просмотров 2 млн
The Unity Tutorial For Complete Beginners
46:39
Просмотров 3,2 млн