<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://pybullet.org/Bullet/phpBB3/app.php/feed/topic/11255" />

	<title>Real-Time Physics Simulation Forum</title>
	
	<link href="https://pybullet.org/Bullet/phpBB3/index.php" />
	<updated>2022-01-13T21:40:04+00:00</updated>

	<author><name><![CDATA[Real-Time Physics Simulation Forum]]></name></author>
	<id>https://pybullet.org/Bullet/phpBB3/app.php/feed/topic/11255</id>

		<entry>
		<author><name><![CDATA[paokakis]]></name></author>
		<updated>2022-01-13T21:40:04+00:00</updated>

		<published>2022-01-13T21:40:04+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43808#p43808</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43808#p43808"/>
		<title type="html"><![CDATA[Re: Jittering and shaking when moving a rigidBody]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43808#p43808"><![CDATA[
I tried with a custom delta time but this didn't work either. I reverted to my old settings. The only solution that I have is pass 0 as substeps in the stepSimulation. Now I have decent results. If there is no problem with that we can consider this item as closed. Thanks for all your support, I really appreciate it<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=13868">paokakis</a> — Thu Jan 13, 2022 9:40 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[paokakis]]></name></author>
		<updated>2022-01-13T10:50:03+00:00</updated>

		<published>2022-01-13T10:50:03+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43806#p43806</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43806#p43806"/>
		<title type="html"><![CDATA[Re: Jittering and shaking when moving a rigidBody]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43806#p43806"><![CDATA[
Hello,<br><br>Thanks for the reply. I'm actually making the Camera follow the spaceship with a Lerp on the position. That's what makes the spaceship shaking. If I don't use Lerp then the Camera is fixed to the spaceship. Then the spaceship is not jittering but the background is. I'm at work at the moment but in afternoon I'll try to add some timing in the action to measure a delta between steps and see if that helps because I debugged the action and saw that for each invocation the delta was the fixed time step from Bullet which makes sense that will move the spaceship twice or trice depending on the current steps. I will update this post with my findings<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=13868">paokakis</a> — Thu Jan 13, 2022 10:50 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[drleviathan]]></name></author>
		<updated>2022-01-13T03:52:49+00:00</updated>

		<published>2022-01-13T03:52:49+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43805#p43805</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43805#p43805"/>
		<title type="html"><![CDATA[Re: Jittering and shaking when moving a rigidBody]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43805#p43805"><![CDATA[
I watched the video.  It looks like you're driving the camera and pushing the spaceship to follow.  That is, I see the camera movement leading the spaceship, and there was one point where the ship lagged the camera by a lot.  I would conclude: you're moving the camera using different timesteps than the simulation.<br><br>Try this hack/test just to see what the movement looks like: slam the camera to be at a rigid fixed point in the ship's local-frame with no flexibility.  If the ship is suffering glitchy rotations then you'll see the starfield and other background objects "glitch", but not the ship.  However know this... when the view angle is very wide it becomes quite hard to detect glitchy movement of the camera with the naked eye... so it may be that with proper camera control any real glitches you have will not be noticeable.<br><br>I think the above is worth trying.  If it looks good it should be possible to add some smooth flex of the camera position in the ship's local-frame by adjusting it as a function of ship linear + angular velocities and thereby regain your "leading camera" movement behavior but without the glitches.<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=11033">drleviathan</a> — Thu Jan 13, 2022 3:52 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[paokakis]]></name></author>
		<updated>2022-01-12T21:07:19+00:00</updated>

		<published>2022-01-12T21:07:19+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43804#p43804</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43804#p43804"/>
		<title type="html"><![CDATA[Re: Jittering and shaking when moving a rigidBody]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43804#p43804"><![CDATA[
Hi Again,<br><br>First of all thanks for all your time that you spend on this. You can take a look to see the video <a href="https://www.youtube.com/watch?v=VLHajXpz2VQ" class="postlink">https://www.youtube.com/watch?v=VLHajXpz2VQ</a> with the jitter so that you will have a better understanding of what is happening. I tried some things with the most promising setting the fixedStep = 1/360. Then the jitter is gone but the physics engine is taking all the CPU resources. So no jitter with stepSize = 0 and with very small fixedStep... The movement with applyForce is fine now, no jitter, only on rotation there is jitter... I am frustrated by it<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=13868">paokakis</a> — Wed Jan 12, 2022 9:07 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[drleviathan]]></name></author>
		<updated>2022-01-11T21:07:51+00:00</updated>

		<published>2022-01-11T21:07:51+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43801#p43801</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43801#p43801"/>
		<title type="html"><![CDATA[Re: Jittering and shaking when moving a rigidBody]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43801#p43801"><![CDATA[
Your quaternion harvesting looks odd to me but if your spaceship expects a <strong class="text-strong">glm::vec4</strong> with the <strong class="text-strong">unnormalized</strong> axis as the <strong class="text-strong">xyz</strong> part and the angle of rotation (in radians) for the <strong class="text-strong">w</strong> part then... I guess it is ok.<div class="codebox"><p>Code: </p><pre><code>static glm::vec4 Rotation;auto q = worldTrans.getRotation();btVector3 v = q.getAxis();Rotation.x = v.x();Rotation.y = v.y();Rotation.z = v.z();Rotation.w = q.getAngle();spaceship-&gt;MotionStateSetRotation(Rotation);</code></pre></div>Meanwhile, this code looks kinda redundant with the one above... in that it appears to be trying to set the rotation of the spaceship again but this time using Euler angles.  With a broad opinionated stroke I always advise people to stay away from Euler angles (and degrees) when possible but the only alternative is to have a deeper understanding of rotational math and I'm aware not everyone wants to spend the effort required to fully understand it.<div class="codebox"><p>Code: </p><pre><code>static btScalar yaw;static btScalar pitch;static btScalar roll;worldTrans.getBasis().getEulerZYX(roll, pitch, yaw, 1);yaw = glm::degrees(yaw);pitch = glm::degrees(pitch);roll = glm::degrees(roll);spaceship-&gt;MotionStateSetYawPitchRoll(yaw, pitch, roll);</code></pre></div>I don't have a good feel for what your glitch actually looks like, or what the stream of quaternions with embedded glitches look like so I can only speculate:<br><br><strong class="text-strong">(1)</strong> Bullet uses a fancy math trick for its rotation extrapolation that I don't actually understand so I wonder if there is a bug therein that is causing the problem... but you say you also saw glitchy behavior when harvesting the rotation directly from the Body so maybe this is not the problem.<br><br><strong class="text-strong">(2)</strong> Do your glitches only show up at low angular speeds?  Or are they visible even at high speeds?  If only at low speeds then I wonder if angular damping is causing it --&gt; try zeroing all angular damping on the spaceship.<br><br><strong class="text-strong">(3)</strong> Are these really big glitches or are they only visible because you have a rigid camera offset to the spaceship?  That is... really small angular glitches might not be very noticeable from a stable camera watching a rotating object... but a camera that rigidly rotates with the object at a big offset might "magnify" small glitches purely by nature of the camera's long lever arm.  In this case maybe you would need to use smoothed camera motion rather than using the raw data.<br><br><strong class="text-strong">(4)</strong> If your render frame rate is aliasing with the simulation then perhaps you only see the glitches when the simulation takes two substeps instead of just one.  You could use rotation math to measure the angle of movement between each frame and look for patterns in that data that correlate with number of substeps.  Perhaps knowledge gained from that measurement would reveal a solution/workaround.  It occurs to me... if you happen to be using an <strong class="text-strong">applyForce()</strong> method to steer your spaceship and you are NOT using it in every substep via an <strong class="text-strong">Action</strong> then I wouldn't be surprised by a rotation glitch whenever the simulation takes two substeps in one step.<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=11033">drleviathan</a> — Tue Jan 11, 2022 9:07 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[paokakis]]></name></author>
		<updated>2022-01-11T15:49:23+00:00</updated>

		<published>2022-01-11T15:49:23+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43799#p43799</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43799#p43799"/>
		<title type="html"><![CDATA[Re: Jittering and shaking when moving a rigidBody]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43799#p43799"><![CDATA[
After a lot of trying I still get the jitter when I set the substeps bigger than 0.<br>substeps :<div class="codebox"><p>Code: </p><pre><code>maxSubsteps = static_cast&lt;int&gt;(delta / (1.f / 60.0f) + 0.5f) + 1;</code></pre></div>motion state :<div class="codebox"><p>Code: </p><pre><code>void SpaceShipMotionState::getWorldTransform(btTransform&amp; worldTrans) const{float yaw, pitch, roll;auto p = spaceship-&gt;MotionStateGetPos();auto r = spaceship-&gt;MotionStateGetRotation();spaceship-&gt;MotionStateGetYawPitchRoll(yaw, pitch, roll);auto pos = btVector3(p.x, p.y, p.z);worldTrans.setOrigin(pos);btQuaternion q;q.setRotation(btVector3(r.x, r.y, r.z), r.w);worldTrans.setRotation(q);//q.setEulerZYX(roll, pitch, yaw);//worldTrans.setRotation(q);}void SpaceShipMotionState::setWorldTransform(const btTransform&amp; worldTrans){auto p = worldTrans.getOrigin();glm::vec3 pos = { p.x(), p.y(), p.z() };spaceship-&gt;MotionStateSetPosition(pos);static glm::vec4 Rotation;auto q = worldTrans.getRotation();btVector3 v = q.getAxis();Rotation.x = v.x();Rotation.y = v.y();Rotation.z = v.z();Rotation.w = q.getAngle();spaceship-&gt;MotionStateSetRotation(Rotation);static btScalar yaw;static btScalar pitch;static btScalar roll;worldTrans.getBasis().getEulerZYX(roll, pitch, yaw, 1);yaw = glm::degrees(yaw);pitch = glm::degrees(pitch);roll = glm::degrees(roll);spaceship-&gt;MotionStateSetYawPitchRoll(yaw, pitch, roll);}</code></pre></div>I only get decent results if I lock the frame rate to 60 fps or disable the substeps (0). Any suggestions?<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=13868">paokakis</a> — Tue Jan 11, 2022 3:49 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[drleviathan]]></name></author>
		<updated>2022-01-10T05:32:57+00:00</updated>

		<published>2022-01-10T05:32:57+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43797#p43797</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43797#p43797"/>
		<title type="html"><![CDATA[Re: Jittering and shaking when moving a rigidBody]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43797#p43797"><![CDATA[
Here is an example minimal custom <strong class="text-strong">MotionState</strong>.  This implementation assumes you have a <strong class="text-strong">GameObject</strong> class outside of Bullet which knows how to get/set its transform.  If your Application is using some other math library (e.g. GLM) outside of the Bullet simulation then you will have to embed transcription logic either in the <strong class="text-strong">GameObject</strong> itself, or here in <strong class="text-strong">MyMotionState</strong> (this work is left as an exercise for the reader).<br><br>You can think of the MotionState as a "bridge object" which communicates between the Body in the simulation and the GameObject in your game logic and render pipeline.  It is a good place to add other Body-vs-GameObject intelligence (e.g. activation, deactivation, changing other Body parameters (gravity, damping, restitution, etc) to help prevent you from leaking Bullet dependencies into other sections of your Application logic which should be physics-engine agnostic.<br><div class="codebox"><p>Code: </p><pre><code>class MyMotionState : public btMotionState{    btRigidBody* m_body;    GameObject* m_gameObject;public:    MyMotionState(btRigidBody* body, GameObject* gameObject)        :   m_body(body), m_gameObject(gameObject)    {}    // getWorldTransform() relays transform from external logic to Bullet.    // It is called by Bullet in two places:    // (1) Once when the Body is created and added to the world.    // (2) Once per substep iff the Body is Kinematic and active.    //    void getWorldTransform(btTransform&amp; worldTrans) const {        // Note: worldTrans is passed by reference        // It is our duty here to copy into it the correct transform as known        // to external logic and Bullet will harvest·        //·        m_gameObject-&gt;getWorldTransform(worldTrans);    }    // setWorldTransform() relays Body transform from the Bullet simulation to the GameObject    // and is called once per substep iff the Body is Dynamic and active.    //    void setWorldTransform(const btTransform&amp; worldTrans) {        // It is our duty here to apply worldTrans to GameObject.        // Note: worldTrans is NOT necessarily the Body's transform as known to Bullet.        // It is an extrapolated transform based on the Body's state at the        // end of the last substep... extrapolated forward into the future (e.g. the remainder        // not yet stepped) according the current Body velocities.        //        m_gameObject-&gt;setWorldTransform(worldTrans);    }};</code></pre></div><p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=11033">drleviathan</a> — Mon Jan 10, 2022 5:32 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[paokakis]]></name></author>
		<updated>2022-01-09T17:52:24+00:00</updated>

		<published>2022-01-09T17:52:24+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43796#p43796</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43796#p43796"/>
		<title type="html"><![CDATA[Re: Jittering and shaking when moving a rigidBody]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43796#p43796"><![CDATA[
Hi again,<br><br>I implemented your first two suggestions with minor improvements. First of all now irrelevant of frame rate I get the same response from the physics engine, for example the maximum velocity of the spaceship is the same with 10 fps and with 60 fps but the jitter is still there. only on low framerates below 30 or at 60 fps I don't get jitter. Can you elaborate a bit on how to create a custom motion state? If you need to see code I can post here. Thanks in advance!<br><br>Edit:<br>after getting the position this way the jitter for the applyForce is gone<div class="codebox"><p>Code: </p><pre><code>btTransform trans;(*body)-&gt;getMotionState()-&gt;getWorldTransform(trans);pos = trans.getOrigin();retPos = glm::vec3(pos.getX(), pos.getY(), pos.getZ());</code></pre></div>The only jitter that remains is that of the rotation. Inside the Action I am updating the rotation this way:<div class="codebox"><p>Code: </p><pre><code>// use mouse position to compute a delta-rotation in spaceship local-framebtQuaternion deltaLocalRotation(yaw, pitch, roll);// get old ship rotationbtTransform transform = body-&gt;getWorldTransform();btQuaternion oldBodyRotation = transform.getRotation();btQuaternion newBodyRotation = oldBodyRotation * deltaLocalRotation;transform.setRotation(newBodyRotation);body-&gt;setWorldTransform(transform);</code></pre></div>I can not use the motion state here, correct? I think here is the jitter of the rotation. This happens every substep.<br>I am calculating the substeps this way:<div class="codebox"><p>Code: </p><pre><code>maxSubsteps = static_cast&lt;int&gt;(fabs(delta / (1.f / 60.0f) + 0.5f)) + 1;</code></pre></div>and that's all. Any ideas on the rotation? Thanks!<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=13868">paokakis</a> — Sun Jan 09, 2022 5:52 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[drleviathan]]></name></author>
		<updated>2022-01-07T20:02:38+00:00</updated>

		<published>2022-01-07T20:02:38+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43791#p43791</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43791#p43791"/>
		<title type="html"><![CDATA[Re: Jittering and shaking when moving a rigidBody]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43791#p43791"><![CDATA[
The delcaration for <strong class="text-strong">btDiscreteDynamicsWorld::stepSimulation()</strong> looks like this:<div class="codebox"><p>Code: </p><pre><code>   ·///if maxSubSteps &gt; 0, it will interpolate motion between fixedTimeStep's   ·virtual int stepSimulation(btScalar timeStep, int maxSubSteps = 1, btScalar fixedTimeStep = btScalar(1.) / btScalar(60.));</code></pre></div>It returns the number of substeps taken.  Harvesting the return value can be useful  in some cases where you need to do post-simulation work but only when the actual substeps taken is non-zero.  Note: if you submit a very tiny <strong class="text-strong">timeStep</strong> that is smaller than a <strong class="text-strong">fixedTimeStep</strong> then the <strong class="text-strong">stepSimulation(</strong>) might not actually make a substep: instead it will accumulate your small <strong class="text-strong">timeStep</strong> and return 0.  It will take a substep later when there is enough time piled up to fit a full <strong class="text-strong">fixedTimeStep</strong>.<br><br>If you supply <strong class="text-strong">maxSubsteps=0</strong> then it goes into "variable step" mode where the simulation moves forward the full step duration, no matter its value.  Such a configuration is <strong class="text-strong">not recommended</strong>.  Only use it if you: <strong class="text-strong">(a)</strong> can guarantee reasonable limits to the range of step durations and <strong class="text-strong">(b)</strong> have a good understanding of the content in the simulation and how physics simulations work.  IBasically: it can lead to a variety of subtle and not so subtle bugs such as: variable success at solving constraints and instabilities that blow velocities to NaN.<br><br>If you really want to eliminate transform glitch then consider this recommended checklist:<br><br><strong class="text-strong">(1)</strong> Use fixed substeps and set the maxSubSteps argument of btDiscreteDynamicsWorld::stepSimulation() to be the max number of substeps that fit into the largest step you expect to ever submit... plus one.  So, if you expect your main game loop to run at 30fps and your substeps are 1/60th of a second, then set <strong class="text-strong">maxSubSteps = 2 + 1</strong>.<br><br><strong class="text-strong">(2)</strong> You should only ever poke velocity or use <strong class="text-strong">applyForce()</strong> inside <strong class="text-strong">SomeCustomAction::updateAction()</strong> where <strong class="text-strong">SomeCustomAction</strong> is a class that derives from <strong class="text-strong">btActionInterface</strong>.  This guarantees that your poking logic happens every substep instead of every step... because Bullet will invoke that <strong class="text-strong">updateAction()</strong> method for every <strong class="text-strong">Action</strong> in the <strong class="text-strong">World</strong> every substep.<br><br><strong class="text-strong">(3)</strong> Create <strong class="text-strong">SomeCustomMotionState</strong> which derives from <strong class="text-strong">btMotionState</strong> and has custom code inside <strong class="text-strong">SomeMotionSubstep::setWorldTransform()</strong> which does the Right Thing with the <strong class="text-strong">worldTransform</strong> argument (e.g. copies that transform to the GameObject and computes the new camera location).  That method will be called every substep on every dynamic <strong class="text-strong">Body</strong> that is "active" and that has a non-null <strong class="text-strong">SomeMotionState</strong> instance.<br><br>If you still experience transform glitches with that system... then something odd is happening: submit relevant code snippets for review and be ready to: describe your render pipeline and justify your math.<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=11033">drleviathan</a> — Fri Jan 07, 2022 8:02 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[paokakis]]></name></author>
		<updated>2022-01-07T18:07:14+00:00</updated>

		<published>2022-01-07T18:07:14+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43789#p43789</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43789#p43789"/>
		<title type="html"><![CDATA[Re: Jittering and shaking when moving a rigidBody]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43789#p43789"><![CDATA[
Thanks for the quick reply @drleviathan. I am indeed using applyForce() but when I use stepSimulation with substeps = 0 <div class="codebox"><p>Code: </p><pre><code>mpDynamicsWorld-&gt;stepSimulation(delta, 0);</code></pre></div> the movement is fine I only get jitter on retrieving the rotation. So when I move my mouse to rotate the Spaceship in my game I get a stutter (only on rotation) every several frames. If I use substeps , 1, 2, 3 or something I get jitter on movement (with applyForce) too. I harvest the position and rotation directly from the rigid body as you say although I tried retrieving a world transform from the motionstate of the rigid body to get position and rotation with the same results. I don't know if that's what you meant... Can you also point me to the way I should calculate the substeps for my application on the stepSimulation?<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=13868">paokakis</a> — Fri Jan 07, 2022 6:07 pm</p><hr />
]]></content>
	</entry>
	</feed>
