Collisions and layers
by Tom Feni · in Torque Game Builder · 06/08/2005 (7:21 pm) · 7 replies
I am a new user so I have load sof questions, but right now I am just curious how to make a set of layers and have one layer as the collision layer, one as an organics layer, and another an obstacle layer..
so right now I have layer 0 as the background, ie grass, dirt paths, so on..
layer 1 is the mountains, water, immovable objetcs that wiull never need to be deleted..
layer 2 is the trees, plants so on that will be scattered around.. :) I just want them on their own layer..
layer 3-12 will be rocks that will be destructable blocking paths to other areas.. this is temporary, I dont know if I need a layer for each destroyable item, or just add them as sprites and have them destroyable that way..
right now I just need to get the collision on the mountains and such working..
I am working on a world map that the player will be able to explore and find different things.. kind of an RPG style game.. but throws the illusion off when you can walk thru the mountain.. :)
I looked thru alot of things but most deal with using images as collisions...
if anyone knows of a basic set up that can lead me the right way I would appreciate it.. :)
thanks
so right now I have layer 0 as the background, ie grass, dirt paths, so on..
layer 1 is the mountains, water, immovable objetcs that wiull never need to be deleted..
layer 2 is the trees, plants so on that will be scattered around.. :) I just want them on their own layer..
layer 3-12 will be rocks that will be destructable blocking paths to other areas.. this is temporary, I dont know if I need a layer for each destroyable item, or just add them as sprites and have them destroyable that way..
right now I just need to get the collision on the mountains and such working..
I am working on a world map that the player will be able to explore and find different things.. kind of an RPG style game.. but throws the illusion off when you can walk thru the mountain.. :)
I looked thru alot of things but most deal with using images as collisions...
if anyone knows of a basic set up that can lead me the right way I would appreciate it.. :)
thanks
About the author
#2

so I wanted to have the player be blocked by these, but have it so I can use just the layer to add collision.. seems it would be the easiest way to do this..
hmm.. is the google search fixed yet?
:)
06/09/2005 (5:52 am)
Hmmm... so in this picture I have mountains, well rock walls.. 
so I wanted to have the player be blocked by these, but have it so I can use just the layer to add collision.. seems it would be the easiest way to do this..
hmm.. is the google search fixed yet?
:)
#3
06/09/2005 (6:04 am)
Have a look at this thread www.garagegames.com/mg/forums/result.thread.php?qt=27393 it deals with setting up collisions on tile layers. From what I remember you can have different collission groups on a per layer basis, although the group applies to all tiles on that layer.
#4
the player still walks thru walls and such..
and gives this error in the console..
fxSceneObject2D::setCollisionActive - Send collision not allowed for this object! (1240).
its weird..
:)
06/09/2005 (7:22 am)
Ok this is where I am at// --------------------------------------------------------------------
// Setup T2D Scene.
// --------------------------------------------------------------------
function setupT2DScene()
{
// Create fxSceneGraph2D.
new fxSceneGraph2D(t2dSceneGraph);
// Associate Scenegraph with Window.
sceneWindow2D.setSceneGraph( t2dSceneGraph );
//%scrollerMap = new fxTileMap2D() { scenegraph = t2dSceneGraph; };
//%scrollerMap.loadTileMap("~/client/maps/worldMap.map");
// Reference Layers.
//%backgroundLayer = %scrollerMap.getTileLayer( 0 );
//%scrollerMap.setSize( "500 500" );
// Set Camera Position to be centered on (0,0) with
// view width/height of (100/80).
//sceneWindow2D.setCurrentCameraPosition( "0 0 100 75" );
//sceneWindow2D.setCurrentCameraPosition( "0 0 100 76" );
%testMap = new fxTileMap2D() {scenegraph = t2dSceneGraph;};
%testMap.loadTileMap("~/client/maps/worldMap.map");
//-----------------------------------
// background
//-----------------------------------
%backlayer = %testMap.getTileLayer(0);
%backlayer.setPosition("100 0");
%backlayer.setTileSize("5 5");
%backlayer.setCollisionActive(false, false);
%backlayer.setCollisionPhysics(true, true);
%backlayer.setCollisionMasks(0xffffffff, 0xffffffff);
//-----------------------------------
// collision
//-----------------------------------
%collayer = %testMap.getTileLayer(1);
%collayer.setPosition("100 0");
%collayer.setTileSize("5 5");
%collayer.setCollisionActive(true, true);
%collayer.setCollisionPhysics(true, true);
%collayer.setCollisionMasks(0xffffffff, 0xffffffff);
//-----------------------------------
// organics
//-----------------------------------
%orglayer = %testMap.getTileLayer(2);
%orglayer.setPosition("100 0");
%orglayer.setTileSize("5 5");
%orglayer.setCollisionActive(false, false);
%orglayer.setCollisionPhysics(true, true);
%orglayer.setCollisionMasks(0xffffffff, 0xffffffff);
// ************************************************************************
//
// Add your custom code here...
//
// ************************************************************************
// Player Data
datablock fxImageMapDatablock2D(playerImageMap)
{
mode = full;
textureName = "~/client/images/player01";
};
$player = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
$player.setGroup( 1 );
$player.setLayer( 1 );
$player.setPosition("20 20");
$player.setSize( "3 6" );
$player.setImageMap( playerImageMap );
//attachThruster( $player, "-0.88 -0.93", 0 );
sceneWindow2D.mount($player, "0 0", 0);
$player.setCollisionActive(true, true);
$player.setCollisionPhysics(true, true);
$player.setCollisionMasks(0xffffffff, 0xffffffff);
$player.setCollisionMaterial(standardMaterial);
// Create a new action map.
new ActionMap(playerMap);
// Bind keys to actions.
playerMap.bindCmd(keyboard, "w", "playerUp();", "playerUpStop();");
playerMap.bindCmd(keyboard, "s", "playerDown();", "playerDownStop();");
playerMap.bindCmd(keyboard, "a", "playerLeft();", "playerLeftStop();");
playerMap.bindCmd(keyboard, "d", "playerRight();", "playerRightStop();");
playerMap.bindCmd(keyboard, "space", "playerFire();", "");
// Activate the action map.
playerMap.push();
}
function attachThruster(%mountObj, %mountPosition, %angle)
{
//Create Player Thruster.
%thruster = new fxParticleEffect2D() { scenegraph = t2dSceneGraph; };
%thruster.loadEffect("~/client/effects/swordeffect.eff");
%thruster.mount( %mountObj, %mountPosition, 0, false );
%thruster.setRotation( %angle );
%thruster.playEffect();
}the player still walks thru walls and such..
and gives this error in the console..
fxSceneObject2D::setCollisionActive - Send collision not allowed for this object! (1240).
its weird..
:)
#5
You don't seem to have an onCollision callback anywhere either, so when two objects do collide, there are no instructions available to tell the objects what to do (unless I overlooked it).
06/09/2005 (7:26 am)
Tile layers can only receive collisions, they cannot send them. So your player can walk into a wall, but the wall cannot walk into the player (if that makes sense).You don't seem to have an onCollision callback anywhere either, so when two objects do collide, there are no instructions available to tell the objects what to do (unless I overlooked it).
#6
Yay!...
now on to textures and the "World Map"
thanks guys.. :)
06/09/2005 (8:19 am)
Ok I got it working.. :)Yay!...
now on to textures and the "World Map"
thanks guys.. :)
#7
Another usefull thing is the .setAtRest() command attached to fxSceneObject2D. So if you ever have problems with using the physics as collision for stoping the player (since it may send them moving slightly in different angles) you can make it call the objects.setAtRest() in the collision callback and disable the physics.
06/09/2005 (8:26 am)
Glad you got it working, good catch Philip. I read this last night and I just got a headache (lol was a long day). Another usefull thing is the .setAtRest() command attached to fxSceneObject2D. So if you ever have problems with using the physics as collision for stoping the player (since it may send them moving slightly in different angles) you can make it call the objects.setAtRest() in the collision callback and disable the physics.
Torque 3D Owner Luke D
Default Studio Name
For collision, I think objects have two choices. First, there's the standard object collision polygon, which defaults to four sides (a rectangle the size of your sprite) but you can increase the number of sides and it will form an ellipse around the sprite, again based on the sprite X/Y size. Alternatively, you can create a custom collision polygon (with setCollisionPolyCustom) that has n sides where you define the vertices for the shape. For something like a mountain, it is likely the standard collision shape won't work, and you'll need to investigate this option. I recall someone making a collision-poly generator, you may wish to search the forum for such a beast. It'll certainly make life easier.
I don't know any advantage to not enabling collision on the mountain sprite itself (with a custom collision poly as described above) and use a separate dedicated layer for collisions. I'm not sure you can even represent collidable areas without a t2dSceneObject anway, so why duplicate?