Issue moving objects that are constrained together.

Post Reply
CodingCoutts
Posts: 3
Joined: Mon Apr 26, 2021 10:01 pm

Issue moving objects that are constrained together.

Post by CodingCoutts »

Hello, the issue I am having has to do with a dynamic object being constrained with a fixed constraint to a kinematic object that are being moved quite drastically as a result of an event in the game I am making. When this event occurs the kinematic object is move from around a Y of -5.f to a Y of 1.f, and the dynamic object that is constrained to the other object is flung up into the air.

My assumption is that because of how far the kinematic object moves, the constraint is acting like a rubber band pulling the dynamic object to the kinematic, and then flinging it further. I have searched through the forum and tried many of different ways to prevent this, manually setting the location for some time, changing the parameters on the constraint, setting the velocity on both the objects to 0 over multiple frames, and more. None of these seem to stop the dynamic object from either flying into the air before returning, appearing where it's supposed to be but in the wrong orientation and then rotating back to where it should be, or slowly moving from the -5 to the y of 1.

I have thought of a few work arounds so I can at least continue with other things for now, but all of them prevent the dynamic object from interacting with other objects in a natural way, and I was hoping someone may have some suggestions how how to handle the dynamic object being flung around.

Thanks in advance!
User avatar
drleviathan
Posts: 744
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Issue moving objects that are constrained together.

Post by drleviathan »

Here are some ideas:

(1) Don't teleport the kinematic object in one step. Instead animate it from A to B quickly, but over several steps. This will give the constraint time to pull the dynamic object to its new location in a smoother way.

(2) If you must teleport the kinematic object in one step, then also teleport the dynamic object such that it maintains its kinematic-object-local offset.

(3) Maybe you don't want a stiff constraint when the kinematic object is teleported. Dynamically soften the constraint to slow its response on teleport and then set it stiff again after things have settled.

(4) If none of those work for you then: I would ask: "Are you sure you really want a constraint there? Maybe you should be doing something else more bespoke, like a custom smart Action or a series of hacky workarounds as final solution."
CodingCoutts
Posts: 3
Joined: Mon Apr 26, 2021 10:01 pm

Re: Issue moving objects that are constrained together.

Post by CodingCoutts »

Unfortunately, I do need to do it in one step, and have been teleporting the dynamic object at the same time, this is all happening during a collision callback method during the step simulation. The problem occurs during the following simulation step, which really doesn't make sense since I also cleared the velocity one those frames(for testing purposes).

I do have one hacky work around, but I think my main issue with being bothered by the fact that even teleporting both objects and clearing the velocities don't seem to affect it.

Does the constraint itself hold onto any notion of velocity or force that I might have missed and need to clear?
User avatar
drleviathan
Posts: 744
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Issue moving objects that are constrained together.

Post by drleviathan »

Ah... it happens in the middle of the step? Maybe try teleporting things right before the next step. That is: set a bool variable teleportBeforeNextStep in the collision callback and outside the step: when teleportBeforeNextStep is true: do the teleport outside of the step itself and set teleportBeforeNextStep back to false.

Really, I'm guessing here. Dunno what kind of state is stored in the constraint solver during the step.
CodingCoutts
Posts: 3
Joined: Mon Apr 26, 2021 10:01 pm

Re: Issue moving objects that are constrained together.

Post by CodingCoutts »

Alright, I'm coming back to this since the work around isn't quite enough any more.


Before I step the simulation I clear all velocities I can find in both the dynamic and kinematic objects, however the delta linear velocity is then increased to a very high amount in "writebackVelocityAndTransform" in btSolverBody.h file, which is then set in the dynamic body and used to predict the dynamic bodies transform in "integrateTransform" in btTransformUtil.h, which is called from "predictIntegratedTransform" in btRigidBody.cpp, and that is called from "integrateTransformsInternal" in btDiscreteDynamicsWorld.cpp when stepping the simulation.

I am still trying to track down when/where/how this delta linear velocity is being calculated, I assume(and may very well be wrong) that it is calculated based on how far the dynamic body moved, but I still don't know how I can affect it's calculation so that my objects behave the way I would like them to. Any help is greatly appreciated.

Thanks in advance!
Post Reply