TGB Physics issues
by Chris Labombard · in Torque Game Builder · 05/10/2006 (3:23 pm) · 24 replies
Ok, continued from Justin's .plan :
I have found the physics engine in TGB to very unstable when dealing with anything beyond the simplest physics interactions. I have also had discussions with several people on irc who own the engine and are having the same issues, as well as seen posts from people on the forums with issues.
The issue is that the physics engine becomes unstable when doing any kind of physics simulation.
2 very notable things:
First, when the game loses focus, the physics just go nuts. If you have objects colliding with any others they gain momentum and bounce all over the place. This happens with both rigid and bounce collision types.
Secondly, I made a contianer with walls that had clamp collision type, and allowed several balls, with collision type rigid (or bounce) to freely fall under gravity to the bottom.
When they come to rest, they jitter, and if you pile too many up they will actually push the bottom ones out of the container in a huge jittery mess.
If you, at this point lose focus of the app, and come back, the balls that were sitting at the bottom, mostly at rest (besides jitter) have momentum and have bounced all over the place.
Also, when an object collides with 2 collision polys butted together it jitters back and forth.
I have tried everything I can think of to fix this, and asked several people who have had the same issues how they solved it, and they hadn't.
I have found the physics engine in TGB to very unstable when dealing with anything beyond the simplest physics interactions. I have also had discussions with several people on irc who own the engine and are having the same issues, as well as seen posts from people on the forums with issues.
The issue is that the physics engine becomes unstable when doing any kind of physics simulation.
2 very notable things:
First, when the game loses focus, the physics just go nuts. If you have objects colliding with any others they gain momentum and bounce all over the place. This happens with both rigid and bounce collision types.
Secondly, I made a contianer with walls that had clamp collision type, and allowed several balls, with collision type rigid (or bounce) to freely fall under gravity to the bottom.
When they come to rest, they jitter, and if you pile too many up they will actually push the bottom ones out of the container in a huge jittery mess.
If you, at this point lose focus of the app, and come back, the balls that were sitting at the bottom, mostly at rest (besides jitter) have momentum and have bounced all over the place.
Also, when an object collides with 2 collision polys butted together it jitters back and forth.
I have tried everything I can think of to fix this, and asked several people who have had the same issues how they solved it, and they hadn't.
About the author
I have been a professional game programmer for over 5 years now. I've worked on virtually every platform, dozens of games and released a few of my own games, including 2 iPhone titles and a title waiting release on Big Fish Games.
#22
The problem now is walking left like in the image below (static sprite is pointing right, but i've actually just finished pressing the left key to move it left), causes your player sprite to burrow into the tiles a little. It get's pushed back out, but not quite enough so that when you try to jump you cannot because the "feet" of the sprite are stuck in the top of the tile.
08/18/2006 (3:45 am)
Setting the $player.setCollisionMaxIterations(2); helped with the sliding substantially, though there still is the odd jitter.The problem now is walking left like in the image below (static sprite is pointing right, but i've actually just finished pressing the left key to move it left), causes your player sprite to burrow into the tiles a little. It get's pushed back out, but not quite enough so that when you try to jump you cannot because the "feet" of the sprite are stuck in the top of the tile.
#23
you have to disable gravity while the ninja should move over the floor. There is some more info in this thread:
http://www.garagegames.com/mg/forums/result.thread.php?qt=45114
The platformer tutorial is a good start too.
08/18/2006 (4:20 am)
Dan,you have to disable gravity while the ninja should move over the floor. There is some more info in this thread:
http://www.garagegames.com/mg/forums/result.thread.php?qt=45114
The platformer tutorial is a good start too.
#24
player.cs
For this code i had the [x] Gravitic checked and Force Scale = 4.0 on the player's physics rollout.
My players and tiles were both 128x128 sprites set to 32x32 in TGB world units.
It behaves as well as anyone could hope witih such simple code.
08/18/2006 (11:49 am)
Ok, here's about as basic as it gets for your standard orthagonal tile collisions. (think mario bros. no slopes )player.cs
function playerNinja::onLevelLoaded(%this, %scenegraph)
{
// Define the player global variable
$pNinja = %this;
// Player movement functions
moveMap.bindCmd(keyboard, "left", "playerLeft();", "playerLeftStop();");
moveMap.bindCmd(keyboard, "right", "playerRight();", "playerRightStop();");
moveMap.bindCmd(keyboard, "space", "playerJump();", "");
// Tell the physics system to check collisions carefully!
$pNinja.setCollisionMaxIterations(2);
}
function playerLeft()
{
$pNinja.moveLeft = true;
}
function playerLeftStop()
{
$pNinja.moveLeft = false;
}
function playerRight()
{
$pNinja.moveRight = true;
}
function playerRightStop()
{
$pNinja.moveRight = false;
}
function playerJump()
{
$pNinja.setLinearVelocityY(-225);
}
function playerNinja::updateMovement(%this)
{
if(%this.moveRight)
{
%this.setLinearVelocityX(40);
}
if(%this.moveLeft)
{
%this.setLinearVelocityX(-40);
}
if(!%this.moveLeft && !%this.moveRight)
{
%this.setLinearVelocityX(0);
}
// Save the current y velocity so it can be reset.
%yVel = $pNinja.getLinearVelocityY();
// Cast a collision downward to see if there is a platform close by.
$pNinja.setLinearVelocityY(100);
// Store the collision response and reset the player velocity
%collision = $pNinja.castCollision(0.005);
$pNinja.setLinearVelocityY(%yVel);
if(%collision $= "")
{
// If there's no collision we need to turn on gravity
$pNinja.setConstantForceY(100);
}
else
{
// otherwise turn it off.
$pNinja.setConstantForceY(0);
}
}
function t2dscenegraph::onUpdateScene()
{
$pNinja.updateMovement();
}For this code i had the [x] Gravitic checked and Force Scale = 4.0 on the player's physics rollout.
My players and tiles were both 128x128 sprites set to 32x32 in TGB world units.
It behaves as well as anyone could hope witih such simple code.
Torque Owner Dan MacDonald
I've included a little test project so you can see what i'm talking about...
www.planetthinktanks.com/dan/ninjatest.zip
...extract the above into your TGB/games folder and then open the corresponding project and run it.
I'd like to not have to resort to pure collisions to do this, the physics system seems like such a natural way to solve this problem.
EDIT: you can check the script file, but the keys are left/right and space.