Issues with Splines Interacting with Rigidbody2D and Colliders

Hello ,

I am currently working on a project where I’m using splines for pathfinding and movement, and I’m encountering some challenges when these splines interact with Rigidbody2D and colliders. I’m hoping to get some insights or solutions to the problems I’m facing.

In my setup, I have game objects that follow spline paths. These objects are equipped with Rigidbody2D components and colliders. However, when I integrate these components, I start experiencing jerky or erratic movements, which is not the smooth path following I expected.

Here are my specific questions and issues:

  • Spline and Rigidbody2D Interaction: How should a Rigidbody2D component be configured to work seamlessly with spline-based movement? Is there a recommended approach to applying forces or velocities when an object is following a spline?

  • Collider Integration: How can I effectively integrate colliders with spline-based movement without causing erratic behavior? I’m particularly interested in understanding the best practices for handling collisions while an object is on a spline path. the thing is i have genral splines to movmenet of players in my shump but sometimes thet hit wals so this interaction is not clear to me - i can desing spsecific spline for each level but i prefer they will have autmatic system to respond whe n hitting some block

    • Dealing with Jerky Movements: What are the common causes of jerky or unnatural movements when using splines with Rigidbody2D and colliders, and how can I resolve these issues? Are there any specific settings or techniques in Unity that could help smooth out the movement?
  • Performance Considerations: Are there any performance implications I should be aware of when using splines with physics components like Rigidbody2D and colliders, especially in a game with multiple moving objects?

  • Any Examples or Resources: If anyone can point me to examples or resources that demonstrate smooth integration of splines with Rigidbody2D and colliders, that would be incredibly helpful.

I’ve tried various configurations and settings, but I’m still struggling to get the smooth, physics-based movement I’m aiming for. Any advice or guidance from those who have tackled similar challenges would be greatly appreciated.

THERE Is this viedo but maybe there are more advanced things today

Thank you very much for your help!

All the normal ways you should move a Rigidbody2D apply. Being a “Spline” makes no difference, it’s just a movement path.

Again, what does the movement of the body have to do with this? “Jerky behaviour” is caused by whatever you’re doing (wrong) really, moving along a “spline” isn’t directly the cause.

I’m not going to answer any more because they are all the same; linking “splines” with problems you’ve created.

The only thing in a 2D physics that moves is a Rigidbody2D and you should always uses its API to do so and never the Transform. If you are causing a Rigidbody2D to move along a spline and its collider hits something to block it then you have to ask yourself what behaviour you want. If you don’t want forces applies when a collider is hit then that’s what a Kinematic body-type is for, again nothing to do with “splines”.

You need to describe the movement behaviour you want i.e. are you wanting to following a spline path exactly? What do you want ot happen when the collider hits something? etc etc.

You can use the TargetJoint2D to continually specify a target position a body should move to and just keep updating that point to the next point on the spline. You can see this in action here where its following a Catmull-rom spline:
https://www.youtube.com/watch?v=AXBaP3mt_Nc

It’s part of my PhysicsExamples2D GitHub repo that demonstrates many features of 2D Physics.
https://github.com/Unity-Technologies/PhysicsExamples2D/blob/master/Assets/Scenes/Joints/TargetJoint2D_FollowCurve.unity

Thx allot - just for clarification - this is my game in this you-tube movie and you can see the enemy ship hitting some obstacles(white capsule) so the question is how and if there is a good way to work with it(maybe it needs pathfinder for 2d or something else)

but basicly i have some obstacle and spline and i want the enemy splined ship to know what to with this obstacles somehow - right now they are passing thru it

i think good behaviour is go aroundf it with next point like you said

i am learning your answer now

Sorry, I’m not following your reply here.

sorry - i fixed my english

i think TargetJoint2D is good way to work with my issue like you can in my movie

i downloaded you git and still have some problem with
i use 2022 lts - maybe i should upgrade?

Assets\PhysicsExamples2D-master\Assets\Scripts\SceneSpecific\Rigidbody2D_SlideAllBodyTypes.cs(11,25): error CS0426: The type name ‘SlideMovement’ does not exist in the type ‘Rigidbody2D’
Assets\PhysicsExamples2D-master\Assets\Scripts\SceneSpecific\Rigidbody2D_SlideGravityNoSlip.cs(9,25): error CS0426: The type name ‘SlideMovement’ does not exist in the type ‘Rigidbody2D’

Just sounds like you’re not using the correct branch for your Unity version. Master was last updated to 2023.1.17f1 (will be updated to 2023.2 soon). There’s 2022, 2021, 2020 and 2019 branches.

Unity should’ve updated it or warnied you about downgrading the project though.

As per the docs:

Each branch represents a specific version of Unity. As features are added in a public release, those features should be represented in that branch and future Unity version branches i.e. branch names of "2019", "2020", "2021" (etc) exist.

https://github.com/Unity-Technologies/PhysicsExamples2D

OK - your work on physics is amazing and i learn allot

now it will be easier for me to adress my problem

i use
Unity Splines
https://docs.unity3d.com/Packages/com.unity.splines@2.5/manual/getting-started-with-splines.html

i played with your amazing git work and learnt allot but still when i use unity spline

for my enemy ships - i also have some obstacles ,like caves and walls, that i dont want the enemy ship to go thru them - for now i cant combine unity spline method with colliders and blocks

any suggetion will be we very helpfull - maube i should use splines for enemy movment or other solution will very needed -

i still didnt understand what you said about TargetJoint2D - i am learning it

enemy to pass thru it but to go around it somehow 9494008--1336675--upload_2023-11-26_18-47-24.png

OK, as i am playing with what you gave here i see there is lots of ontresting stuff that can happen with physcs2d and rigidbody but not sure if unity spline can join this party…

i realy not sure about what i say - honestly i see i dont undersatnd the whole thing

so how would you recommened creating waves of enemys with some curves and patterns and at the same time do it in game situation thaat contains colliders and block that do have physcics properties?

thank you allot for the help

Splines don’t have anything to do with physics. They’re just a set of points and tangents with APIs (usually) to determine positions and directions based on these.

The only thing that really matters here is you move your rigidbody along the spline’s path using the rigidbody API. Most likely using Rigidbody.MovePosition(). Or if you want them to potentially bounce off colliders you might move them around with forces or .velocity.

If you want enemies to avoid solid object then you’ll have to work out an actual AI navigation solution here. Though I think there’s a reason you seldom see this in schump games.