Collision Groups
by John Klotz · in Torque Game Builder · 06/09/2006 (10:23 am) · 5 replies
I am trying to create a statement that calls upon certain functions depending on which objects are colliding. Is the following proper syntax? Should this work?
I do this and it doesn't seem to recognize trapgroup or platformgroup. Do i have to declare these groups in script or call them from the game somehow? How do I go about doing this?
I do this and it doesn't seem to recognize trapgroup or platformgroup. Do i have to declare these groups in script or call them from the game somehow? How do I go about doing this?
function t2dSceneObject::onCollision(%srcObj, %dstObj, %srcRef,
%dstRef, %time, %normal, %contactCount, %contacts)
{
if(%srcObj = $playergroup && %dstobj = $platformgroup)
{
collideplayerplatform(%normal);
}
if(%srcObj = $playergroup && %dstobj = $trapgroup)
{
playertrap(%normal);
}
}
#2
06/09/2006 (11:13 am)
And you'd probably be better off doing something like this:function t2dSceneObject::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
// collision has occured
switch (%srcObj.getGraphGroup())
{
// player has hit something
case $playerGroup:
switch (%dstObj.getGraphGroup())
{
// hit the pltform group
case $platformGroup:
collideplayerplatform(%normal);
// hit the trap group
case $trapGroup:
playertrap(%normal);
}
}
}Not sure about any performance benefits, but it's definately easier to read.
#3
What is the difference between using GraphGroup and .class.
%srcObj.graphGroup == $playergroup
vs.
%srcObj.class == $playergroup
both work the same for me
06/09/2006 (11:49 am)
Ehh, thats how i initially went after this problem and it wouldn't work for the life of me so I decided on using some If statements for the time being.What is the difference between using GraphGroup and .class.
%srcObj.graphGroup == $playergroup
vs.
%srcObj.class == $playergroup
both work the same for me
#4
That is pure coincident. I guess your $playergroup is 0.
Class specifies the class/namespace this object belongs to.
06/09/2006 (12:08 pm)
Quote:
both work the same for me
That is pure coincident. I guess your $playergroup is 0.
Class specifies the class/namespace this object belongs to.
#5
1) My character can jump while airborn
My solution to this was to set a value to when he is colliding with the ground and to say you can only run the jump function when this value is present but Im not quite sure where to place these values.
2) My other collision functions dont fire and I receive a million echos of 'collision function' no matter what I am colliding with, whether it be a trap or anything. Can you see any reason that these function aren't firing when called upon?
These are the functions that I am trying to pass to in certain instances. None are complete yet, I am just trying to get it down where they are all being used at the correct times.
I realize the $ground = 0; line in playerjump is pretty useless in telling the computer the character is off the ground since it gets set to 1 again before the next jump anyways but where would you suggest putting this or what would you suggest in order to make it so my character can oonly jump when in contact with the platform?
06/09/2006 (12:39 pm)
Thanks for all the help so far guys, I appreciate it. So far this is what I have. I have two problems. 1) My character can jump while airborn
My solution to this was to set a value to when he is colliding with the ground and to say you can only run the jump function when this value is present but Im not quite sure where to place these values.
2) My other collision functions dont fire and I receive a million echos of 'collision function' no matter what I am colliding with, whether it be a trap or anything. Can you see any reason that these function aren't firing when called upon?
function t2dSceneObject::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
//playergroup = 1
//platformgroup = 2
//trapgroup = 3
//playercheese = 4
//blockgroup = 5
if( (%srcObj.graphgroup == $playergroup) && (%dstobj.graphgroup == $platformgroup) )
$ground = 1; //new
if($jump < 1)
{
collideplayerplatform(%normal);
}
else if(($jump = 1) && ($ground = 1))
{
playerjump(%normal);
}
else if( (%srcObj.graphgroup == $playergroup) && (%dstobj.graphgroup == $trapgroup) )
{
playertrap(%normal);
}
else if( (%srcObj.graphgroup == $playergroup) && (%dstobj.graphgroup == $playercheese) )
{
echo("cheesicle");
}
}These are the functions that I am trying to pass to in certain instances. None are complete yet, I am just trying to get it down where they are all being used at the correct times.
function collideplayerplatform(%normal)
{
echo("colision function");
%move = $moveright - $moveleft;
$myplayer.setlinearvelocityX(%move * $myplayer.runspeed);
}
function playertrap(%normal)
{
echo("player trap");
//$myplayer.setlinearvelocity(-10, -10);
//$myplayer.setconstantforce( 10, 10);
$myplayer.safedelete();
}
function playerjump(%normal)
{
$myplayer.setlinearvelocityY(-10 * $myplayer.jumpheight);
$myplayer.setConstantForce( 0, 140 );
$ground = 0;
}I realize the $ground = 0; line in playerjump is pretty useless in telling the computer the character is off the ground since it gets set to 1 again before the next jump anyways but where would you suggest putting this or what would you suggest in order to make it so my character can oonly jump when in contact with the platform?
Torque Owner Michael Woerister
function t2dSceneObject::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts) { if( (%srcObj.graphGroup == $playergroup) && (%dstobj.graphGroup == $platformgroup) ) { collideplayerplatform(%normal); } if( (%srcObj.graphGroup == $playergroup) && (%dstobj.graphGroup == $trapgroup) ) { playertrap(%normal); } }A single '=' is the assignment operator. '==' is for comparison. '$=' is for comparison of strings.