Game Development Community

Sinking into the Ground

by James Petruzzi · in Torque Game Builder · 04/12/2005 (8:19 pm) · 11 replies

I'm working on a 2d Side scroller first off. I have SetConstantForce on my player simulating gravity and pushing him downward. I then made the ground and set up the collision stuff. Now he spawns, hits the ground and slowly sinks in, so first i tried setLinearVelocityY=0 but that didnt work. So then I tried the SetAtRest() and he doesnt sink, but i cant move left or right or jump then. If you need code ill be more than happy to supply, thanks!

#1
04/12/2005 (8:34 pm)
Code would be useful. My first thought, though, is that you may be using the onCollision callback to set the player linearVelocity to 0. Unless you have a specific reason to go that route, it may be more desirable to use use collision physics instead.
#2
04/12/2005 (8:51 pm)
OK, here is my Player code:

$player.setConstantForce("0 9800", 1);

// Set player's collision info: 
$player.setGroup( 1 ); 
$player.setLayer( 1 ); 
$player.setCollisionActive( true, true ); 
$player.setCollisionMaterial( playerMaterial ); 
$player.setCollisionPolyCustom( 6, "-0.1786 -0.8925 0.7500 -0.4301 0.6071 0.9570 -0.7143 0.9032 -0.4107 0.6989 -0.2500 -0.8602" );
$player.setCollisionMasks( BIT(2), BIT(2) ); 
$player.setCollisionCallback( true );

Player Collision Material

datablock fxCollionMaterialDatablock2D(playerMaterial)
{
	friction = 0;
	restitution = 0;
	relaxation = 0.5;
	density = 1;
	damping = 0;
};

Ground Code

$groundLayer.setPosition( "0 30" ); 
	$groundLayer.setSize( "120 50" );
	$groundLayer.setWrap( true, false );
	//%bgmountainsLayer.setAutoPan( "2 0" );
	
	$groundLayer.SetLayer( 2 );
   	$groundLayer.SetGroup( 2 );
   	$groundLayer.SetCollisionActive( false, true );
   	$groundLayer.SetCollisionMaterial( immovableMaterial );
   	$groundLayer.SetCollisionMasks( BIT(1), BIT(1) );
	$groundLayer.SetCollisionCallback( true );

and Collision Code

function fxSceneObject2D::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts ) 
{
	
	if (%srcObj == $player)
	{
		$player.setLinearVelocityY(0);
		echo("\nsrcCollision Detected\n");
	}
	else if (%dstObj == $player)
	{
		echo("\ndstCollision Detected\n");
	}
	else
	{
		%srcObj.safeDelete();
		%dstObj.safeDelete();
	}
}

thanks again..
#3
04/12/2005 (9:17 pm)
You'll probably want to set the collision physics

.setCollisionPhysics(true, true);

for both


and set the ground

.setImmovable();
#4
04/12/2005 (9:25 pm)
Awesome, you people are damned geniuses! One small glitch is that he appears to pivot when he comes into contact with the next tile. I wouldnt even bring it up except the search on this site sucks, but i know i saw something like setRotation that solved someones problem at some point. Thanks!!!
#5
04/12/2005 (11:55 pm)
@James: You could use
$player.setMaxAngularVelocity(0);

to make sure the player won't pivot.
#6
04/13/2005 (12:02 am)
The hitching at the tile contact points is a known bug, and I'm pretty certain Melv's got it licked for the next update (tomorrow?! :-p).
#7
04/13/2005 (2:28 am)
The hitching issue cannot be fixed until the new file-format is in.

I'm essentially restricted by what changes I can make to objects without breaking existing objects.

There's lots of pending bugs to go in, all fixed, just not in the next update.

Just thought I'd also say that lots of people won't be interested in the rigid-body stuff, especially for "classic" platformers. Again, I'll be adding other stock collision responses such as "clamp", "sticky", "bounce" for standard collisions. This is similar to the way the world-limit works at present.

- Melv.
#8
04/13/2005 (7:06 am)
Wow ok, you guys are fast. I'll try that out, but will my character still slow down when he comes into contact with the seam now or just ignore it (I'm at work now so I cant check it :().

@Melv:
My other question is i just ordered a copy of OS 10.4 and i was wondering if you all had the chance to play with it yet, and if there was any loss of functionality with the upgrade?
Thanks for the fast and functional replies all!
#9
04/14/2005 (10:09 am)
@Melv:
Quote:Just thought I'd also say that lots of people won't be interested in the rigid-body stuff, especially for "classic" platformers.

Why wouldn't someone want to use the rigid-body physics for a platformer. That's what I was planning on doing because it sounds like an easy way to go... or am I missing something?

[end hijack of thread]
#10
04/14/2005 (10:15 am)
(unless I'm mistaken) I think hes referencing how the character responds when it hits a platform... that a clamp type of response will be more appropriate vs a bounce up at the appropriate angle with a correct physics response... the collision responses will be the same just the physics model can then be customized specifically for individual objects :)

Right now you can do the setAtRest thing to set your own sort of "clamp" method... though he seems to be planning on supporting internal physics options that will do this for you
#11
04/16/2005 (6:39 am)
@Matt: It won't affect you at all. Matthew is correct, I'm simply adding other responses on top of Ridid-Body. Most people wouldn't want to use rigid-body physics because it is more complex to balance all the reactions/forces. Quite often, people just want fairly simple behaviour for these types of games. If you want to do a little more work and have a more realistic reaction then go for it, that's why it's in there and will stay. :)

- Melv.