Problems with castCollision method
by Alexander Bierbrauer · in Torque Game Builder · 05/16/2006 (5:57 am) · 5 replies
Hi again,
I'm having serious trouble with the castCollision method of a t2dAnimatedSprite.
Here's my code:
%oldVelY = %player.getLinearVelocityY();
%player.setLinearVelocityY(100);
%collision = %player.castCollision(0.2);
%player.setLinearVelocityY(%oldVelY);
if (%collision $= "")
{
setPlayerFalling(%player);
}
else echo("updatePlayer:" @ %collision);
I wanna check if there's still some ground under the player.... but the collision never happens!!

That's an example image where no collision happens of course, but the collision doesn't happen even when the player stands upon the left block ! But !!! regular onCollision-methods are getting called.
any help !?
I'm having serious trouble with the castCollision method of a t2dAnimatedSprite.
Here's my code:
%oldVelY = %player.getLinearVelocityY();
%player.setLinearVelocityY(100);
%collision = %player.castCollision(0.2);
%player.setLinearVelocityY(%oldVelY);
if (%collision $= "")
{
setPlayerFalling(%player);
}
else echo("updatePlayer:" @ %collision);
I wanna check if there's still some ground under the player.... but the collision never happens!!

That's an example image where no collision happens of course, but the collision doesn't happen even when the player stands upon the left block ! But !!! regular onCollision-methods are getting called.
any help !?
#2
05/17/2006 (1:59 am)
I used it with beta2 (or beta1?) to do exactly the same as you and it worked perfectly. Any chance that you pass the wrong object to your function? (so that %player is in fact not the player)
#3
Here's the whole function:
function updatePlayer(%player)
{
if(%player.jumping == true)
{
if(mAbs(%player.getPositionY() - %player.jumpStartPosY) > $GAME::PLAYER_JUMP_HEIGHT)
{
%player.jumping = false;
setPlayerFalling(%player);
}
}
%oldVelY = %player.getLinearVelocityY();
echo("player old vel: " @ %oldVelY);
%player.setLinearVelocityY($GAME::PLAYER_FALLING_SPEED);
%collision = %player.castCollision(1.0);
%player.setLinearVelocityY(%oldVelY);
echo("updatePlayer:" @ %collision);
}
maybe it has something to with my collision settings ??
Here are the settings for the player:
$player.setSize($GAME::PLAYER_SIZE_X SPC $GAME::PLAYER_SIZE_Y);
$player.setCollisionActive(true, true);
$player.setCollisionPhysics(false, false);
$player.setCollisionResponse(CLAMP);
$player.setCollisionCallback(true);
$player.setCollisionMaxIterations(2);
$player.setLayer($GAME::PLAYER_LAYER);
$player.setGraphGroup($GAME::PLAYER_GROUP);
$player.setCollisionMasks(BIT($GAME::BLOCK_FALLING_GROUP), BIT($GAME::BLOCK_FALLING_LAYER));
$player.setCollisionPolyCustom(4, "-0.2 -0.3 0.3 -0.3 0.3 0.9 -0.2 0.9");
But I don't think that this is the problem, 'cause the normal onCollision callback works fine
Is there a real life example outthere ? ;)
05/17/2006 (4:11 am)
I've checked the player variable again, and yes it is the player ;)Here's the whole function:
function updatePlayer(%player)
{
if(%player.jumping == true)
{
if(mAbs(%player.getPositionY() - %player.jumpStartPosY) > $GAME::PLAYER_JUMP_HEIGHT)
{
%player.jumping = false;
setPlayerFalling(%player);
}
}
%oldVelY = %player.getLinearVelocityY();
echo("player old vel: " @ %oldVelY);
%player.setLinearVelocityY($GAME::PLAYER_FALLING_SPEED);
%collision = %player.castCollision(1.0);
%player.setLinearVelocityY(%oldVelY);
echo("updatePlayer:" @ %collision);
}
maybe it has something to with my collision settings ??
Here are the settings for the player:
$player.setSize($GAME::PLAYER_SIZE_X SPC $GAME::PLAYER_SIZE_Y);
$player.setCollisionActive(true, true);
$player.setCollisionPhysics(false, false);
$player.setCollisionResponse(CLAMP);
$player.setCollisionCallback(true);
$player.setCollisionMaxIterations(2);
$player.setLayer($GAME::PLAYER_LAYER);
$player.setGraphGroup($GAME::PLAYER_GROUP);
$player.setCollisionMasks(BIT($GAME::BLOCK_FALLING_GROUP), BIT($GAME::BLOCK_FALLING_LAYER));
$player.setCollisionPolyCustom(4, "-0.2 -0.3 0.3 -0.3 0.3 0.9 -0.2 0.9");
But I don't think that this is the problem, 'cause the normal onCollision callback works fine
Is there a real life example outthere ? ;)
#4
mattl (at) garagegames.com
I've used castCollision a lot and don't think I've run into any problems with it.
05/17/2006 (8:17 am)
Feel free to send me your working directory and I'll check it out if/when I get a chance...mattl (at) garagegames.com
I've used castCollision a lot and don't think I've run into any problems with it.
#5
The problem was that I didn't set the collision masks proberbly ! The onCollision-method didn't care about it, so I thought everything was right but castCollision takes care !
I've submitted a TGB resource containing a small castCollision demo for everyone:
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10501
05/18/2006 (2:55 am)
Whoohaa! I solved my problem !The problem was that I didn't set the collision masks proberbly ! The onCollision-method didn't care about it, so I thought everything was right but castCollision takes care !
I've submitted a TGB resource containing a small castCollision demo for everyone:
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10501
Torque Owner Alexander Bierbrauer