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
  Wheel Collider to propel along Spline Phunyun 1 21 08-23-2019, 10:09 PM
Last Post: _Aka_
  Curvy Spline mover is jerky BlankMauser 5 87 08-16-2019, 09:31 PM
Last Post: _Aka_
  Camera wobbles on too long spline (100km+) Vectorvision 10 315 08-01-2019, 12:35 PM
Last Post: _Aka_
  Closest point From a Ray (a line), to the spline UsernameHed 5 190 07-31-2019, 03:57 PM
Last Post: _Aka_

Forum Jump: