player onCollision with the ground?
by Lee Latham · in Torque Game Engine · 04/14/2009 (8:58 pm) · 9 replies
I'm trying to put stuff into Armor::onCollision that happens when the player makes contact with the ground, but it never seems to get called.
For example, if I drop my player from a great height, he stops at the ground, so there's collision happening, but yet Armor::onCollision doesn't seem to get called.
Any ideas why this might be the case? I know it's a bit odd...any input would be greatly appreciated!
For example, if I drop my player from a great height, he stops at the ground, so there's collision happening, but yet Armor::onCollision doesn't seem to get called.
Any ideas why this might be the case? I know it's a bit odd...any input would be greatly appreciated!
#2
onImpact gets called for terrain, but only if the speed is greater than
minImpactSpeed = 45;
defined in playerData
the current onImpact uses the speedDamageScale to apply damage according to how fast you are moving.
That should get you started in the right direction.
04/15/2009 (7:10 am)
off the top of my head:onImpact gets called for terrain, but only if the speed is greater than
minImpactSpeed = 45;
defined in playerData
the current onImpact uses the speedDamageScale to apply damage according to how fast you are moving.
That should get you started in the right direction.
#3
04/15/2009 (7:16 am)
@Lee, it might help if you describe why you want to use the callback. Are you running a script onCollision? What is the effect you want to achieve?
#4
Typically onCollision is called when you run into some object, the callback processes what needs to be done so far as picking it up, mounting a vehicle, etc.
The onImpact callback is triggered when you run into something at a greater speed/velocity than what you have set in your player datablock for: minImpactSpeed. Only impacts at speeds greater than those set in that field will trigger the onImpact callback. NOTE: speedDamageScale works alongside of that in order to scale the amount of possible damage done by how fast you were going.
EDIT: it is possible to determine whether or not you've run into something other than terrain through use of Typemasks -- I typically check for player vs player impacts, player vs fixed object impacts, player vs terrain impacts, etc. etc. Player vs vehicle impacts can be a lot of fun with a little vector math and applyImpulse() ;)
04/15/2009 (7:59 am)
I think you might be confusing the differences between Armor::onCollision() and Armor::onImpact(). Typically onCollision is called when you run into some object, the callback processes what needs to be done so far as picking it up, mounting a vehicle, etc.
The onImpact callback is triggered when you run into something at a greater speed/velocity than what you have set in your player datablock for: minImpactSpeed. Only impacts at speeds greater than those set in that field will trigger the onImpact callback. NOTE: speedDamageScale works alongside of that in order to scale the amount of possible damage done by how fast you were going.
EDIT: it is possible to determine whether or not you've run into something other than terrain through use of Typemasks -- I typically check for player vs player impacts, player vs fixed object impacts, player vs terrain impacts, etc. etc. Player vs vehicle impacts can be a lot of fun with a little vector math and applyImpulse() ;)
#5
@Steve I think you're right, I should have put more detail.
Specifically I'm trying to call the player's onCollision when he impacts with TSstatics. I'll do various things, such as shooting him away from the object with some force. In some places, I'm even thinking of having him walk over a TSstatic that sends him up in the air, for a pogo-stock effect.
Anyway, since TSstatics don't have an onCollision method, I figured I'd do it in the player's one.
(I have experimented with using StaticShapes and using the onCollision there, but I just can't get projectiles to collide with StaticShapes).
I'm not currently using any type of typemask in script. ATM I've just got an echo statement in the players onCollison, and I can't seem to trigger that when colliding with TSstatics.
I have dug around in the source (which I don't really understand, but nonetheless I can occasionally get away with murder in there hehe) and I see some typemasks in player.cc, but haven't had any luck pretty much just trying every logical combinations I can think of.
Hopefully that clarifies my question--sorry for being so vague. I have tried setting minimpactspeed and such to 0 to no avail. He collides with the TSstatics fine, I just can't seem to get it to trigger the callback.
note: I'm using polysoup collision for the TSstatics. Hmmm.
04/15/2009 (3:32 pm)
Thanks all for the helpful responses.@Steve I think you're right, I should have put more detail.
Specifically I'm trying to call the player's onCollision when he impacts with TSstatics. I'll do various things, such as shooting him away from the object with some force. In some places, I'm even thinking of having him walk over a TSstatic that sends him up in the air, for a pogo-stock effect.
Anyway, since TSstatics don't have an onCollision method, I figured I'd do it in the player's one.
(I have experimented with using StaticShapes and using the onCollision there, but I just can't get projectiles to collide with StaticShapes).
I'm not currently using any type of typemask in script. ATM I've just got an echo statement in the players onCollison, and I can't seem to trigger that when colliding with TSstatics.
I have dug around in the source (which I don't really understand, but nonetheless I can occasionally get away with murder in there hehe) and I see some typemasks in player.cc, but haven't had any luck pretty much just trying every logical combinations I can think of.
Hopefully that clarifies my question--sorry for being so vague. I have tried setting minimpactspeed and such to 0 to no avail. He collides with the TSstatics fine, I just can't seem to get it to trigger the callback.
note: I'm using polysoup collision for the TSstatics. Hmmm.
#6
Another thing to keep in mind is that TSStatic shapes are typically meant to be fixed objects in which no interaction occurs, ie. no callbacks or script methods are given to them.
With that being said you can use the onImpact callback to determine what you've just run into. Setting minImpactSpeed to 0 caused me to take damage every single time that I jumped or bumped into something.
04/15/2009 (5:00 pm)
It occurred to me a couple of hours later that you really wouldn't want the onCollision callback to fire upon every collision with the Terrain, otherwise it would be called everytime you took a step. I didn't look, but I would assume that the engine ignores the terrain so far as the onCollision callback is concerned. Another thing to keep in mind is that TSStatic shapes are typically meant to be fixed objects in which no interaction occurs, ie. no callbacks or script methods are given to them.
With that being said you can use the onImpact callback to determine what you've just run into. Setting minImpactSpeed to 0 caused me to take damage every single time that I jumped or bumped into something.
function Armor::onImpact(%this, %obj, %collidedObject, %vec, %vecLen)
{
echo("c4Armor::onImpact -> "@ %this.getName() @" for "@ %obj.client.nameBase @" just ran into "@ %collidedObject.getName() @"ObjID#"@ %collidedObject);
// believe it not but sometimes you can run into yourself ???
if (%obj == %collidedObject)
%obj.damage(0, VectorAdd(%obj.getPosition(),%vec), %vecLen * %this.speedDamageScale, "ImpactNonPlayer");
// here we've impacted either the Terrain, a StaticShape, or an Interior
else if (%collidedObject.getType() & ($TypeMasks::TerrainObjectType | $TypeMasks::StaticShapeObjectType | $TypeMasks::InteriorObjectType))
%obj.damage(0, VectorAdd(%obj.getPosition(),%vec), %vecLen * %this.speedDamageScale, "ImpactNonPlayer");
// here we've impacted with a TSStatic shape
else if (%collidedObject.getType() & ($TypeMasks::StaticTSObjectType))
%obj.damage(0, VectorAdd(%obj.getPosition(),%vec), %vecLen * %this.speedDamageScale, "ImpactPlayer");
// we've just impacted another player
else
%obj.damage(0, VectorAdd(%obj.getPosition(),%vec), %vecLen * %this.speedDamageScale, "ImpactPlayer");
}Quote:I'll do various things, such as shooting him away from the object with some force. In some places, I'm even thinking of having him walk over a TSstatic that sends him up in the air, for a pogo-stock effect.Just my 2c, but you might want to consider using a combination of Trigger + applyImpulse() for that, or using a PhysicalZone that surrounds your object.
#7
I set minImpactSpeed to 1 (zero caused it to hang the game when I hit the polysoup) and I'm getting nice little echos out now, so I know I can "do stuff" with it. Now I'll just need to figure out how to remove the head shaking when that happens, which I imagine comes down to another db value somewhere.
Just my 2c, but you might want to consider using a combination of Trigger + applyImpulse() for that, or using a PhysicalZone that surrounds your object.
I hear ya. I actually use that sort of thing extensively in my big game. I'm just experimenting with some crazy ideas for a "little game".
I think this will give me the basis I'm looking for, though. I'm still kinda "disturbed" that I can't just use onCollision in the player, but my feelings aren't what's important, here lol :-)
edit: I meant to say camera-shaking, not head bobbing on impact
04/15/2009 (5:22 pm)
@Michael: I think you've found the key for me, thanks! :-)I set minImpactSpeed to 1 (zero caused it to hang the game when I hit the polysoup) and I'm getting nice little echos out now, so I know I can "do stuff" with it. Now I'll just need to figure out how to remove the head shaking when that happens, which I imagine comes down to another db value somewhere.
Just my 2c, but you might want to consider using a combination of Trigger + applyImpulse() for that, or using a PhysicalZone that surrounds your object.
I hear ya. I actually use that sort of thing extensively in my big game. I'm just experimenting with some crazy ideas for a "little game".
I think this will give me the basis I'm looking for, though. I'm still kinda "disturbed" that I can't just use onCollision in the player, but my feelings aren't what's important, here lol :-)
edit: I meant to say camera-shaking, not head bobbing on impact
#8
04/15/2009 (10:07 pm)
The ground impact camera shake is controlled from the player datablock:groundImpactMinSpeed = 10.0; groundImpactShakeFreq = "4.0 4.0 4.0"; groundImpactShakeAmp = "1.0 1.0 1.0"; groundImpactShakeDuration = 0.8; groundImpactShakeFalloff = 10.0;I had actually forgotten about those, especially the groundImpactMinSpeed (which determines at which impact speed the camera will shake). The ShakeFreq/Amp/Duration/Falloff all work much as they do for the camera shake from explosions.
#9
It does kindof bring home the fact that the onImpact stuff wasn't really intended to replace onCollision, but supplement it. I still kindof feel like there may be other hidden costs to using it this way down the road.
I've played (I think) with all the player datablock values and can't seem to convince it to actually call onCollision when landing on the ground or colliding with a TSstatic. It works hunky-dory with vehicles, rigidshapes, etc. but not tsstatics or interiors.
04/15/2009 (11:09 pm)
Thanks Michael, I found it. Yeah actually I was digging around in the source to make disable it altogether, but that proved a little complicated, so I just zeroed out those values, basically.It does kindof bring home the fact that the onImpact stuff wasn't really intended to replace onCollision, but supplement it. I still kindof feel like there may be other hidden costs to using it this way down the road.
I've played (I think) with all the player datablock values and can't seem to convince it to actually call onCollision when landing on the ground or colliding with a TSstatic. It works hunky-dory with vehicles, rigidshapes, etc. but not tsstatics or interiors.
Associate Steve Acaster
[YorkshireRifles.com]