Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


Gasimzada

Member Since 11 Feb 2012
Offline Last Active May 10 2014 12:59 AM

#5114873 Bullet physics undefined behavior with a dummy simulation

Posted by Gasimzada on 06 December 2013 - 09:40 AM

I can't believe this tongue.png I have been thinking the problem is with my timestep for the past 2 days. I want to know though. What is the advantage of having "inactive" objects?




#5114857 Bullet physics undefined behavior with a dummy simulation

Posted by Gasimzada on 06 December 2013 - 08:59 AM

I have asked this question couple days ago. I thought I fixed the issue since I don't keep my program on the moment I start it but I found something I can't fix.

 

Here is the scenario:

  • I have a sphere object thats centered at (0.0, 2.0, -5.0). It has a 1KG mass and has a Sphere Collision Shape with zero radius.
  • The world gravity force is (0,0,0). I know for a fact that the object is just "sitting in the emptiness"
  • There are three input events I attach to my object: if I press 'W' the rigid body's linear velocity is set to (0.0,0.0,-10.0);
  • I added a "profiler" to check out the position and linear velocity of the object every frame, and linear velocity during key press.​​​​
    • ​For each frame it prints "ID. posX posY posZ LinearVelocityX LinearVelocityY LinearVelocityZ" (ID is for keeping count)
    • For each input event it prints "new velocity: LinearVelocityX, LinearVelocityY, LinearVelocityZ"

The problem:

 

When I constantly move the object, there is no problem; everything works fine. However, the object doesn't move if I keep it idle for around 5 seconds or more.

 

The test and results:

 

I run the program. Wait for 5 seconds and then press "W" the linear velocity gets zeroed out after the simulation step even if the linear velocity was set during the event firing:

240. 0 2 -5 0 0 0
241. 0 2 -5 0 0 0
242. 0 2 -5 0 0 0
new velocity: 0, 0, -10
243. 0 2 -5 0 0 0
244. 0 2 -5 0 0 0
245. 0 2 -5 0 0 0
246. 0 2 -5 0 0 0
247. 0 2 -5 0 0 0

The code:

Physics system update:

 void BulletPhysicsSystem::update(double dt) {
        mWorld->stepSimulation(1/60.0f,5);
        
        //This is the profiling
        btTransform transform; btVector3 v(mComponents[0]->mRigidBody->getLinearVelocity());
        mComponents[0]->mRigidBody->getMotionState()->getWorldTransform(transform);
        std::cout << ++i << ". " << transform.getOrigin().x() << " " << transform.getOrigin().y() << " " <<transform.getOrigin().z() << " ";
        std::cout << v.x() << " " << v.y() << " " << v.z() << "\n";
    }

Main loop:

sf::Clock clock;

while(mRunning) {
      mCurrentState->processInput();
      mCurrentState->update(clock.getElapsedTime().asSeconds());
      //This function updates the physics
      mRenderWindow.clear(); mRenderWindow.pushGLStates();
      mCurrentState->render(); mRenderWindow.popGLStates(); clock.restart(); mRenderWindow.display();
}

A video from my scene with the problem in it:

https://www.youtube.com/watch?v=jtKGKj5xOiU

 

Additional notes:

The input and Graphics works in my system which gets the position from the rigid body of the bullet physics component. But from what I see that the problem is in my time step but I don't know how to fix it. Even a fixed time step doesn't seem to show a result that at least moves the object. What am I doing wrong?

 

I am so desperate to fix this issue. If any more information is needed please tell me.

 

Thanks,
Gasim




#5114178 how to implement stable timestep for systems (Bullet Physics and SFML for tim...

Posted by Gasimzada on 03 December 2013 - 05:16 PM

Yes thats what it does. Here is the wiki from Bullet Physics:

 

 

 

It's important that timeStep is always less than maxSubSteps*fixedTimeStep, otherwise you are losing time. Mathematically,

timeStep < maxSubSteps * fixedTimeStep

When you are calculating what figures you need for your game, start by picking the maximum and minimum framerates you expect to see. For example, I cap my game framerate at 120fps, I guess it might conceivably go as low as 12fps.

 

After you asked the question, I couldn't stop myself from digging into the source code of Bullet:

if (maxSubSteps)
	{
		//fixed timestep with interpolation
		m_fixedTimeStep = fixedTimeStep;
		m_localTime += timeStep;
		if (m_localTime >= fixedTimeStep)
		{
			numSimulationSubSteps = int( m_localTime / fixedTimeStep);
			m_localTime -= numSimulationSubSteps * fixedTimeStep;
		}
	} 

So it looks like the "semi-fixed timestep" from the article I was referring to.




#5111807 Component Based Entity Design communication between components and systems

Posted by Gasimzada on 25 November 2013 - 06:20 AM

I have designed Component Based Entity (CBE) System and I am stuck in communicating in between components and systems (by that I mean, component-component, component-system, system-system). I communicate between components and systems through events. Each component and system registers functions per event name. There are also global events that handle rendering or capturing.

 

Components and systems know nothing about each other.

 

Here is a what I have so far:

 

There are 2 systems: TileLevelSystem and InputSystem. The TileLevelSystem holds a stack of entities in each tile; and the InputSystem captures the input and sends the mapped event to the systems and PlayerComponents. When a PlayerComponent added to an Entity, the entity gets automatically added to the InputSystem. When TilePositionComponent gets added to an Entity, the entity gets added to a tile in the TileLevelSystem. There is also a PassableComponent component that checks if a character can walk through an entity.

  1. If one types 'w', the input fires event "moveUp"; the fired event is sent to a the entity with the PlayerComponent
  2. The entity passes the "moveUp" event to all the components.
  3. TilePositionComponent receives it, and sends an event "updatePosition(currentX, currentY, currentX, currentY-1)" to TileLevelSystem. 
  4. TileLevelSystem sends event "isPassable" to an entity in the new position (if there is one); if the event returns true, the player moves to the new position and the "updatePosition" event returns true. Then the TilePositionComponent's currentX and currentY gets updated.
  5. Then everything gets rendered.

I am currently working on picking items that are pickable. I have created two components: InventoryComponent and PickableComponent. InventoryComponent accepts event "pickItem", and PickableComponent accepts event "isPickable". There are two approaches that I have in mind.

 

First one is sending an event "pickItemFromCurrentTile", which gets accepted by TilePositionComponent. After TilePositionComponent does all its communications with the TileLevelSystem, the component sends a "pickItem" event to the InventoryComponent with Entity as an argument, which adds the entity to the inventory.

 

The second one is creating a return class for Event which holds a state; then sending "pickItemCurrentTile", which returns the entity and I add it to the pickItem.

 

I am writing this system to understand how CBE System flow really works. If you think my whole design is wrong, please tell me. I want to make this system very clear and flexible before I do anything else.

 

Thanks,

Gasim

 

 




PARTNERS