<?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/13057" />

	<title>Real-Time Physics Simulation Forum</title>
	
	<link href="https://pybullet.org/Bullet/phpBB3/index.php" />
	<updated>2020-08-26T15:58:41+00:00</updated>

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

		<entry>
		<author><name><![CDATA[whitwhoa]]></name></author>
		<updated>2020-08-26T15:58:41+00:00</updated>

		<published>2020-08-26T15:58:41+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43083#p43083</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43083#p43083"/>
		<title type="html"><![CDATA[Re: Bullet Physics resetting rigidbody origin after manually setting]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43083#p43083"><![CDATA[
Resolved this by completely removing, resetting, and readding the rigid body to the dynamics world via the following:<br><div class="codebox"><p>Code: </p><pre><code>if (this-&gt;input.keyLeftControl &amp;&amp; !this-&gt;crouching){this-&gt;crouching = true;this-&gt;crouchNeedFall = true;//Set scalebtVector3 scale = this-&gt;clientBody-&gt;getCollisionShape()-&gt;getLocalScaling();scale.setY(crouchScale);this-&gt;clientBody-&gt;getCollisionShape()-&gt;setLocalScaling(scale);this-&gt;ghostObject-&gt;getCollisionShape()-&gt;setLocalScaling(scale);this-&gt;collisionWorld-&gt;dynamicsWorld-&gt;updateSingleAabb(this-&gt;clientBody);auto clientOrigin = this-&gt;clientBody-&gt;getWorldTransform().getOrigin();btVector3 newOrigin = btVector3(clientOrigin.getX(), clientOrigin.getY() - 0.525, clientOrigin.getZ());this-&gt;collisionWorld-&gt;dynamicsWorld-&gt;removeRigidBody(this-&gt;clientBody);this-&gt;clientBody-&gt;clearForces();this-&gt;clientBody-&gt;setLinearVelocity(btVector3(0, 0, 0));this-&gt;clientBody-&gt;setAngularVelocity(btVector3(0, 0, 0));this-&gt;clientBody-&gt;getWorldTransform().setOrigin(newOrigin);this-&gt;ghostObject-&gt;getWorldTransform().setOrigin(newOrigin);this-&gt;collisionWorld-&gt;dynamicsWorld-&gt;addRigidBody(this-&gt;clientBody);}</code></pre></div><p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=13318">whitwhoa</a> — Wed Aug 26, 2020 3:58 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[whitwhoa]]></name></author>
		<updated>2020-08-26T15:16:08+00:00</updated>

		<published>2020-08-26T15:16:08+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43082#p43082</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43082#p43082"/>
		<title type="html"><![CDATA[Bullet Physics resetting rigidbody origin after manually setting]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43082#p43082"><![CDATA[
Working on a character controller in Bullet Physics engine that uses a rigidbody, specifically crouch functionality. I've run into an issue where Bullet is resetting the origin of the world transform for the body back to what it was before I set it manually. This appears to be happening when stepSimulation() is called. It feels like there may be a parameter that I'm not setting, although what it could be evades me at this time. I have uploaded <a href="https://www.youtube.com/watch?v=kV6zbIR0N-0&amp;feature=youtu.be" class="postlink">the following video which shows exactly what I'm trying to explain</a>:<br><ul><li>0:00 - 09:00 no input provided</li></ul><ul><li>10:00 crouch key pressed (collision shape scales correctly, then is translated back to origin instead of staying on ground where it was set)</li></ul><ul><li>12:00 crouch key released</li></ul><ul><li>13:00 crouch key pressed</li></ul><ul><li>16:00 forward movement key pressed (applying a force to the body causes it to fall back to ground)</li></ul>Below is the code where I'm scaling the collision object and transforming the rigidbody origin:<div class="codebox"><p>Code: </p><pre><code>if (this-&gt;input.keyLeftControl &amp;&amp; !this-&gt;crouching){    this-&gt;crouching = true;    //Set scale    btVector3 scale = this-&gt;clientBody-&gt;getCollisionShape()-&gt;getLocalScaling();    scale.setY(crouchScale);    this-&gt;clientBody-&gt;getCollisionShape()-&gt;setLocalScaling(scale);    this-&gt;ghostObject-&gt;getCollisionShape()-&gt;setLocalScaling(scale);    this-&gt;collisionWorld-&gt;dynamicsWorld-&gt;updateSingleAabb(this-&gt;clientBody);    auto clientOrigin = this-&gt;clientBody-&gt;getWorldTransform().getOrigin();    btVector3 newOrigin = btVector3(clientOrigin.getX(), clientOrigin.getY() - 0.525, clientOrigin.getZ());    clientBody-&gt;getWorldTransform().setOrigin(newOrigin);    this-&gt;ghostObject-&gt;getWorldTransform().setOrigin(newOrigin);    }</code></pre></div>After this code executes, the origin is correct until stepSimulation() executes, at which point the rigidbody object is transformed back to the origin it was at prior to the above code block being executed.<br><br>Is there anything glaringlyobvious that stands out to anyone that I may be overlooking?<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=13318">whitwhoa</a> — Wed Aug 26, 2020 3:16 pm</p><hr />
]]></content>
	</entry>
	</feed>
