Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Moving Rigidbodies On Spline With Force
#1
Im working on a racing game, where the user is not allowed to go left or right, being solely dependent on the trajectory of the spline. I am currently applying a force to the rigidbody of the car but the car doesnt seem to be following the trajectory in a very precise way. After two/three turns into the race, the car is already far from the spline.

I am familiar RigidBodySplineController, however, this example was made very much with the geometry of the track itself in mind, and the "pull towards the center" doesnt work well in my case. I tried various combinations but at best I have a very non-natural movement.

Having previously used velocity with a simple spline controller, I am sure that the issue with tangent/direction changing all the time is something manageable but am having a very tough time figuring out how to have the exact same behavior with forces.

Please let me know if you could help me with figuring this issue out as im sure a lot of users have bumped into this issue. I also have the feeling that I may be overcomplicating things and am missing something obvious.

Thank you
Cezar
Reply
#2
After delving deeper into the issue, I clarified the problem and I hope the maintainers will help me solve it.

When pushing the object on a spline using Force, the force vector stays the same across the entire motion until a = 0. That means that on a right turn, your direction may be (-1, 0, 0) yet given that the force starts at (0, 0, 1), the force is in entirely the wrong direction and the object can't possibly stay on the spline.

The obvious work around is to have a subclass that would simulate pushing a force. Mainly, the subclass would only calculate the speed of an object pushed by F over delta time, and return only the velocity of the object. That velocity can be passed directly to a Spline/Volume controller.

Unfortunately, I do not have the familiarity with the internal CurvySpline doings to write this extension. Was wondering if the maintainers could think of an easy fix.
Reply
#3
Yes, having rigidbodies behave like you want while simultaneous being locked to an invisible path is tricky, that's why we don't provide a full-fledged RB controller - it just won't feel right for everyone.

So creating your own custom controller is the way to go and it's quite easy to do so (read about it here). Most of time it's sufficient to override just ApplyTransformPosition()/ApplyTransformRotatiion() and add your physics manipulation code there.

Also, I've seen others getting good results by using multiple GameObjects: one or more SplineControllers that follow the path and a separate rigidbody being kept in relation to them.

Tbh I'm not sure if I fully understand the issues you're having, perhaps you could show some screenshots or even send me a scene (by mail) to have a closer look. But I'm quite sure that it's possible to get the behaviour you're after.

Jake
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Curvy Line Renderer for UI Spline? gekido 1 1 3 hours ago
Last Post: _Aka_
  Get position of all control points for a spline gekido 1 2 3 hours ago
Last Post: _Aka_
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_
  GO can't fit end of the spline GameDeveloperek4123 3 13 03-04-2024, 11:06 AM
Last Post: _Aka_

Forum Jump: