Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SOLVED - What's the better way to track Soft Body position?
#1
Hello everyone!

Does anyone knows a good way to track SB position reliably and smoothly?

https://youtu.be/rYDHcSxnrws
Here in the video you can see:
- a blue translucent SB
- a gray sphere, a child of the SB
- a camera (well, you cannot see it but it's there obviously)

SB is moved via constant AddForce(direction * force * Time.deltaTime,ForceMode.Acceleration). The sphere is just a child, no code there. The camera tracks SB transform position and lerps there with a factor of 0.1.

As you can see, the sphere is always ahead of SB and is jerking all the time, while the camera moves smoothly (not at the top speeds) but is always behind. Is there a way track that SB so it will look smooth? I don't know, maybe the average position of every particle will work. Still have to figure how this will work. But still, looking for a good way to make tracking SB as smooth as possible.
Reply
#2
(31-08-2020, 09:46 PM)the-lander Wrote: Hello everyone!

Does anyone knows a good way to track SB position reliably and smoothly?

https://youtu.be/rYDHcSxnrws
Here in the video you can see:
- a blue translucent SB
- a gray sphere, a child of the SB
- a camera (well, you cannot see it but it's there obviously)

SB is moved via constant AddForce(direction * force * Time.deltaTime,ForceMode.Acceleration). The sphere is just a child, no code there. The camera tracks SB transform position and lerps there with a factor of 0.1.

As you can see, the sphere is always ahead of SB and is jerking all the time, while the camera moves smoothly (not at the top speeds) but is always behind. Is there a way track that SB so it will look smooth? I don't know, maybe the average position of every particle will work. Still have to figure how this will work. But still, looking for a good way to make tracking SB as smooth as possible.

I have a similar setup where a camera needs to follow a softbody smoothly and the only way I found to make it smooth was to use softbody.GetMass(out centrePosition) and update the camera in LateUpdate. Worth a try at least if you haven't already.
Reply
#3
For this kind of thing it is quite important to understand how and when physics are updated in relation to the render loop, and the order in which updates happen in Unity. Physics interpolation also plays an essential role.

If using a ObiFixedUpdater component (which is the most common case), softbody transform position/rotation is updated in Update(), after all calls to FixedUpdate() for that frame have been made.

However, this position/rotation is not interpolated between physics updates, so if your solver has interpolation enabled (see:http://obi.virtualmethodstudio.com/tutorials/obisolver.html) the transform will always be a bit ahead of it and "jitter" compared to the visual position of the particles.

This is because physics state interpolation works by linearly blending between the current physics state and the previous physics state, depending on how much wall clock time hasn't been simulated yet. This solves the problem caused by the fact that in most engines (Unity being no exception) physics aren't updated in sync with the render loop.
So particle positions/orientations can be anywhere between the values for the current frame, and the values for the previous frame. Since the transform is always using the current values, it means it will always be ahead of the particles. Note that this is not unique to Obi, physics state interpolation works this way in all physics engines (Unity's built-in physics, Unreal's, etc).

So in case you want to parent stuff to the softbody and have it track it perfectly, either:

- Disable interpolation entirely. This will result in "stutter" when simulating in FixedUpdate() though, as physics state is not updated in sync with rendering.
- If you have interpolation enabled, interpolate the transforms too so that they move in sync with the particles.

There's more advanced camerawork options you could use, of course: you could extrapolate softbody position from its current velocity to determine where it's moving to, and aim the camera there so that the player sees where it's going to move next, not where it comes from (as that does not give the player much information, and can make the camera feel unresponsive). Based on your video, this is the way to go imho.
Reply
#4
Quote:use softbody.GetMass(out centrePosition) and update the camera in LateUpdate.
That didn't work for me for some reason.



Quote:interpolate the transforms too so that they move in sync with the particles.
How should I interpolate the transforms properly?
Reply
#5
So, it might be the hot day under the bright sun, or just me, not so bright of a person trying to do several things at once.

The things that helped me:

  1. Turning interpolation off in the Obi Slover
  2. Turning off all the lerps for the camera and the sphere
camera.position = player.transform.position in an Update works just fine at this point. I'm speechless and need a rest. https://youtu.be/Trkk-7HcsSk


Thank you for your help guys )!
Reply