Collectable objects slow down the player
by Philip Mansfield · in Torque Game Builder · 04/11/2006 (4:48 am) · 5 replies
When my player either jumps into or falls onto a collectable item, their movement is impeded.
When falling, the player stops for a short time, the collectible is deleted, and then they carry on falling. When jumping into a collectable, the jump stops once the player hits the item, and starts falling again. Moving left or right into the collectable seems to be OK.
I basically want the collectables to just disappear without impeding the players progress. I'm using bits of code from the platform TDN tutorial, and here are the relevant parts:
Player definition:
Collectable definition:
Collision stuff:
I think that's all. I've tried different collision responses, but I haven't had much luck. If anyone can point out the error of my ways, I'd be grateful.
When falling, the player stops for a short time, the collectible is deleted, and then they carry on falling. When jumping into a collectable, the jump stops once the player hits the item, and starts falling again. Moving left or right into the collectable seems to be OK.
I basically want the collectables to just disappear without impeding the players progress. I'm using bits of code from the platform TDN tutorial, and here are the relevant parts:
Player definition:
function initPlayer()
{
$player = new t2dStaticSprite() { scenegraph = t2dScene; };
$player.setImageMap(facefront);
$player.setGraphGroup( $playerGroup );
$player.setLayer( $playerLyer );
$player.setSize( "63 64" );
$player.setCollisionActive(true, true);
$player.setCollisionPhysics(true, false);
$player.setCollisionResponse(CLAMP);
$player.setCollisionCallback(true);
$player.setCollisionMaxIterations(2);
$player.setCollisionMasks(BIT($platformGroup)|BIT($eggGroup), BIT($platformLayer)|BIT($eggLayer));
$player.setWorldLimit("clamp", -256, -232, 256, 184, true);
$player.moveSpeed = 100;
$player.jumpHeight = 45;
$player.setCollisionPolyPrimitive(4);
$player.setCollisionPolyScale("0.3 1");
$player.setMaxAngularVelocity(0);
}
function playerJump()
{
$player.setLinearVelocityY(-10 * $player.jumpHeight);
}Collectable definition:
function placeEggs()
{
for (%i=1; %i<=24; %i++)
{
eval("%eggPos=$levelData.egg"@%i@";");
%blueEgg = new t2dStaticSprite() { scenegraph = t2dScene; };
%blueEgg.setImageMap(blueegg);
%blueEgg.setGraphGroup( $eggGroup );
%blueEgg.setLayer( $eggLayer );
%blueEgg.setCollisionPolyPrimitive (8);
%blueEgg.setCollisionPolyScale ("0.5 0.75");
%blueEgg.setCollisionActive(false, true);
%blueEgg.setPosition(%eggPos);
%blueEgg.setSize( "36 36" );
}
}Collision stuff:
function t2dSceneObject::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
switch (%srcObj.getGraphGroup())
{
case $playerGroup:
switch (%dstObj.getGraphGroup())
{
case $eggGroup:
$runSurface = -1;
%dstObj.safeDelete();
}
}
}I think that's all. I've tried different collision responses, but I haven't had much luck. If anyone can point out the error of my ways, I'd be grateful.
Torque Owner Michael Woerister
function initPlayer() { $player = new t2dStaticSprite() { scenegraph = t2dScene; }; $player.setImageMap(facefront); $player.setGraphGroup( $playerGroup ); [b]$player.setLayer( $playerLyer ); // typo?? [/b] $player.setSize( "63 64" ); $player.setCollisionActive(true, true); $player.setCollisionPhysics(true, false); $player.setCollisionResponse(CLAMP); $player.setCollisionCallback(true); $player.setCollisionMaxIterations(2); [b]$player.setCollisionMasks(BIT($platformGroup), BIT($platformLayer)); // egg group/layer removed[/b] $player.setWorldLimit("clamp", -256, -232, 256, 184, true); $player.moveSpeed = 100; $player.jumpHeight = 45; $player.setCollisionPolyPrimitive(4); $player.setCollisionPolyScale("0.3 1"); $player.setMaxAngularVelocity(0); }function placeEggs() { for (%i=1; %i<=24; %i++) { eval("%eggPos=$levelData.egg"@%i@";"); %blueEgg = new t2dStaticSprite() { scenegraph = t2dScene; }; %blueEgg.setImageMap(blueegg); %blueEgg.setGraphGroup( $eggGroup ); %blueEgg.setLayer( $eggLayer ); [b]%blueEgg.setCollisionLayers( $playerLayer ); %blueEgg.setCollisionGroups( $playerGroup ); %blueEgg.setCollisionCallback(true);[/b] %blueEgg.setCollisionPolyPrimitive (8); %blueEgg.setCollisionPolyScale ("0.5 0.75"); [b]%blueEgg.setCollisionActive(true, false);[/b] %blueEgg.setPosition(%eggPos); %blueEgg.setSize( "36 36" ); } }function t2dSceneObject::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts) { switch (%srcObj.getGraphGroup()) { [b]case $eggGroup:[/b] switch (%dstObj.getGraphGroup()) { [b]case $playerGroup:[/b] $runSurface = -1; [b]%srcObj.safeDelete();[/b] } } }I think this should work, but I am not sure.
-Michael