Game Development Community

Tile Map Collision Problem

by Ted "darkhitman" Nubel · in Torque Game Builder · 03/11/2005 (7:46 pm) · 7 replies

I get the feeling that there's something really obvious that I'm missing here, but I can't figure out what.

I was trying to get my player object (this is a test game, so I'm using all images that came w/ T2D) to collide with the tile map I made, but to no avail. So I turned on the debug for the tile layer (not map) and the object, but I don't see any collision boxes around the tiles. I copied this code from a source and changed it so that the tiles would actually show up, so I don't see why it wouldn't work. Note that this is the code after a variety of rewrites; I didn't originally use brickMap and Layer -- they came from the copying part that I was too lazy to rewrite.

$brickMap = new fxTileMap2D() { scenegraph = t2dSceneGraph; };
	$brickMap.loadTileMap("~/client/maps/leveltest.map");
	$brickLayer = $brickMap.getTileLayer(0);
	$brickLayer.setPosition("0 -125");

	// setup the layer collisions
	$brickLayer.setGroup(1);
	$brickLayer.setLayer(1);
	$brickLayer.setSize( "100 80" );
	$brickLayer.setPosition( "0 5" );
	$brickLayer.setCollisionActive(false, true);
	$brickLayer.setCollisionMaterial(immovableMaterial);
	$brickLayer.setCollisionMasks(BIT(2), BIT(2));
	$brickLayer.setCollisionCallback(true);
	$brickLayer.setCollisionPhysics(true, false);
	$brickLayer.setDebugOn(BIT(5));

The bounding box shows up fine for my player, so I don't see why this isn't working. Any ideas? Again, it's probably really obvious, but after a few hours I gave up and decided to post here.

-darkhitman

#1
03/11/2005 (8:22 pm)
I'm also a n00b at this, but I want to take a stab at it since, that is what I'm working on as of late...

How many layers do you have on your leveltest.map?
Are there any collideable objects on layer 0 of leveltest.map?
#2
03/12/2005 (6:45 am)
Just one layer, and there should be collideable objects there. How can I check?
#3
03/12/2005 (7:08 am)
When you run your example, launch the tile editor.

Try loading your map by going to file > load tile map (cross your fingers, doesn't always work)

If it did, check to see if there are any green boxes around any objects (to include the border of the map. If there is no border around the map, click view > tile info). If you still do not see green boxes, you may not have any collideable objects. To place a collideable object, select the object you wish to place from the selection screen on the top right. Click the red X to make it a green check mark. This adds collision info when you add an object. Place the object and ensure a green box surrounds the newly placed object. Save your progress, reload T2D and see if that helps.
#4
03/12/2005 (7:39 am)
Like I said, something really obvious. Thanks, it works now.

On a side note, I seriously thought that was the exit button for the layer. I guess not.
#5
03/12/2005 (7:54 am)
Yeah, I thought it was too. I was afraid to click that X the first time.
#6
03/13/2005 (2:29 am)
Also, if you use "ctrl"+left-mouse-click on a tile you have placed, it brings up the "Edit Tile" dialog. You can then click on "Collision Active?" to toggle the collision on and off.

- Melv.
#7
03/13/2005 (8:35 pm)
The ctrl + left click works quite efficiently :)