Game Development Community

Sprite positions change when turning on collision

by Philip Mansfield · in Torque Game Builder · 04/10/2006 (11:54 am) · 3 replies

Not sure what's happening here, but here's a piccy showing the problem:
www.philspcmods.com/images/colprob.jpgThe top half of the image is with collisions enabled on that sprite, and the lower half is without collisions enabled.

As you can see, the left edge of the platform moves over when I enable collisions. The platform is created from a few sprites, and other platforms created in the same way do not show this behaviour. It's just this one platform.

Here's the code:
function placePlatforms()
{
	for (%i=1; %i<=$levelData.numPlatforms; %i++)
	{
		eval("%platlength=$levelData.p"@%i@"length;");
		eval("%platPos=$levelData.p"@%i@"pos;");

		%leftend = new t2dStaticSprite() { scenegraph = t2dScene; };
		%leftend.setImageMap(endplatform);
		%leftend.setGraphGroup( $platformGroup );
		%leftend.setLayer( $platformLayer );
//		%leftend.setCollisionActive(false, true);
		%leftend.setSize( "16 16" );
		%leftend.setPosition(%platPos);

		for (%j=1; %j<=%platlength; %j++)
		{
			%middle = new t2dStaticSprite() { scenegraph = t2dScene; };
			%middle.setImageMap(midplatform);
			%middle.setGraphGroup( $platformGroup );
			%middle.setLayer( $plaformLayer );
			%middle.setSize( "16 16" );
			%middle.setPosition( getWord(%leftend.getPosition(),0)+(getWord(%leftend.getSize(),0)*%j) SPC getWord(%leftend.getPosition(),1));
			%middle.setCollisionActive(false, true);
		}

		%rightend = new t2dStaticSprite() { scenegraph = t2dScene; };
		%rightend.setImageMap(endplatform);
		%rightend.setGraphGroup( $platformGroup );
		%rightend.setLayer( $platformLayer );
		%rightend.setSize( "16 16" );
		%rightend.setPosition( getWord(%leftend.getPosition(),0)+(getWord(%leftend.getSize(),0)*%j) SPC getWord(%leftend.getPosition(),1));
		%rightend.setFlip(true, false);
		%rightend.setCollisionActive(false, true);
	}
}

The line that's commented out is the one that's causing the trouble. If I run it uncommented, the left part of the first platform shifts over. All the other platforms appear in the right place.

For reference:
$levelData.numPlatforms = 5;

p1length = 4;
p1pos = "100 -125";

p2length = 2;
p2pos = "-180 -80";

p3length = 3;
p3pos = "-20 50";

p4length = 2;
p4pos = "-200 80";

p5length = 5;
p5pos = "115 125";

#1
04/10/2006 (12:33 pm)
Here's a thought:

You gon't have a custom collision polygon, so it's using the rectangle the size of the sprite. The guy on the end is colliding with the others and resolving itself by moving off to a a safe distance. It's just a guess, but that's been my interaction with the collision system.
#2
04/10/2006 (12:50 pm)
I'll give it a go, thanks. If that's the case though, the other platform sprites should also be colliding with each other, and they're not moving...
#3
04/11/2006 (3:37 am)
Not sure what I changed in the end, but the platform is behaving itself now. I've got another problem now, but I think that needs a new thread.