Collision %normal behaviour
by C. N. · in Torque Game Builder · 11/08/2005 (10:27 am) · 4 replies
Hi,
I've got a top-down rpg going at the moment. I wanted to implement some behaviours to the game objects depending on their collision normals. Before I started this, I decided to see what the normals were returning on collisions. So I went into the onCollision function and echoed the %normal. This seems to work fine: if I'm walking left and hit a wall it reports the %normal as "1.0 0.0", right as "-1.0 0.0", etc for all the other directions. So to achieve a certain effect depending on the %normal, I am doing:
if(%srcObj == $playerImage)
{
if(%normal == "1.0 0.0") { echo("1 and 0"); }
if(%normal == "0.0 1.0") { echo("0 and 1"); }
if(%normal == "-1.0 0.0") { echo("-1 and 0"); }
if(%normal == "0.0 -1.0") { echo("0 and -1"); }
echo("normal" SPC %normal);
...
}
What happens is, if I'm walking upwards then hit a wall, or walking downwards and hit a wall, it reports the Y axis %normal in both Y directions, but on the X axis it reports only the one normal (they way I want it to behave). So when the player is walking upwards or downwards and hits a wall, it echos:
0 and 1
0 and -1
Anyone know what is happening?
Thanks for any input.
I've got a top-down rpg going at the moment. I wanted to implement some behaviours to the game objects depending on their collision normals. Before I started this, I decided to see what the normals were returning on collisions. So I went into the onCollision function and echoed the %normal. This seems to work fine: if I'm walking left and hit a wall it reports the %normal as "1.0 0.0", right as "-1.0 0.0", etc for all the other directions. So to achieve a certain effect depending on the %normal, I am doing:
if(%srcObj == $playerImage)
{
if(%normal == "1.0 0.0") { echo("1 and 0"); }
if(%normal == "0.0 1.0") { echo("0 and 1"); }
if(%normal == "-1.0 0.0") { echo("-1 and 0"); }
if(%normal == "0.0 -1.0") { echo("0 and -1"); }
echo("normal" SPC %normal);
...
}
What happens is, if I'm walking upwards then hit a wall, or walking downwards and hit a wall, it reports the Y axis %normal in both Y directions, but on the X axis it reports only the one normal (they way I want it to behave). So when the player is walking upwards or downwards and hits a wall, it echos:
0 and 1
0 and -1
Anyone know what is happening?
Thanks for any input.
#2
11/08/2005 (7:16 pm)
Hmm, that's what I thought, but nothing happens when I use the $= (probably because the strings aren't equal, lol). I do get most of the results I'm aiming for when I use the ==, though. Strange...
#3
Another thing is that if you have a bounding box that's not a square then T2D might try to report multiple normals since it could collide in multiple points.
Honestly I'm just guessing, so this might not help you at all. :)
11/08/2005 (8:28 pm)
You should definitely be using $= compares for that specific code. But instead of comparing the entire string, why not extract the axis you want to test? Ie:if ( GetWord( %normal, 0 ) == 1.0 ) { echo( "X 1.0" ); }
if ( GetWord( %normal, 1 ) == 1.0 ) { echo( "Y 1.0" ); }
...etc...You'll notice I'm using == here because if you extract the values you can treat it as a numerical comparison rather than a string as in your original code.Another thing is that if you have a bounding box that's not a square then T2D might try to report multiple normals since it could collide in multiple points.
Honestly I'm just guessing, so this might not help you at all. :)
#4
11/09/2005 (12:20 am)
Superb! Thanks alot, Jason. That's exactly what I was looking for! (^_^)
Torque Owner Adam Larson