ShapeBase onCollision
by Howard Dortch · in Torque Game Engine · 04/29/2005 (7:46 am) · 5 replies
The onCollision function for my player gets called when the play collides with an object StaticShapeData type. What I want to do is have a collision event called if the static shape collides with me. I looked in the engine and see a onCollision method for ShapeBase. I assume the shape base here is my player. Is a static shape not derived from shape base?
I put echo statements in my player onCollision and had the object collide with me and the event never happens. If I move my player then I get the onCollision event.
All this is a result of the doors resource. When the door closes on my player no collision events happen, the event only happens when I move my player.
Is it possible for onCollision event for the static shape to be called if it hits my player? If so, how would I do that?
I put echo statements in my player onCollision and had the object collide with me and the event never happens. If I move my player then I get the onCollision event.
All this is a result of the doors resource. When the door closes on my player no collision events happen, the event only happens when I move my player.
Is it possible for onCollision event for the static shape to be called if it hits my player? If so, how would I do that?
#2
Furthermore, as you've discovered, Players only check for collisions if they're moving. At about line 2437 in player.cc there appears to be a motion check. F32 speed is set to the length of the mVelocity vector, and if it's 0 we break and no collision detection is performed.
So...
I don't think so. Not without adding a fair bit of code to ShapeBase.
You could disable that speed check in player.cc... That should solve your problem. But then all Players constantly check for collisions, moving or not. I wonder if it might not have other undesirable side affects as well. I don't think that would be the ideal solution.
Instead, might I suggest two simple script solutions?
If you don't mind if the player is able to hold open a door, you could put a trigger around your door. Then only allow the door to close if there's no player in the trigger.
If you want the door to close regardless of who's in the way, I'd suggest using a modified version of the script function radiusDamage to push Players out of the way. Something like this:
Apply a small force from the center of the door. It doesn't even have to be enough to push the player clear, just enough to get them moving. Then their collision detection should kick in.
Edit: A few more script changes.
Edit again: It occurs to me that a trigger might be better than that radius script, since a sphere is probably not the ideal detection region in this case. It would make more sense I think to itterate through all objects in the trigger, and push them out.
05/02/2005 (1:56 am)
StaticShape is derived from ShapeBase, yes. From a quick look through the source, I don't think either StaticShape or ShapeBase perform any collision detection. They provide convex hulls for other objects to collide with, but they do not themselves check for collisions. I don't think either Shape class was designed with the intent that they would move.Furthermore, as you've discovered, Players only check for collisions if they're moving. At about line 2437 in player.cc there appears to be a motion check. F32 speed is set to the length of the mVelocity vector, and if it's 0 we break and no collision detection is performed.
So...
Quote:Is it possible for onCollision event for the static shape to be called if it hits my player?
I don't think so. Not without adding a fair bit of code to ShapeBase.
You could disable that speed check in player.cc... That should solve your problem. But then all Players constantly check for collisions, moving or not. I wonder if it might not have other undesirable side affects as well. I don't think that would be the ideal solution.
Instead, might I suggest two simple script solutions?
If you don't mind if the player is able to hold open a door, you could put a trigger around your door. Then only allow the door to close if there's no player in the trigger.
If you want the door to close regardless of who's in the way, I'd suggest using a modified version of the script function radiusDamage to push Players out of the way. Something like this:
function radiusForce(%position, %radius, %force)
{
// Use the container system to iterate through all the objects
// within our radius. We'll apply an impulse to all ShapeBase
// objects.
InitContainerRadiusSearch(%position, %radius, $TypeMasks::ShapeBaseObjectType);
while ((%targetObject = containerSearchNext()) != 0) {
%dist = vectorLen(%targetObject.getPosition() - %position);
if (%dist > %radius)
continue;
// Apply the impulse
if (%force) {
%impulseVec = VectorSub(%targetObject.getWorldBoxCenter(), %position);
%impulseVec = VectorNormalize(%impulseVec);
%impulseVec = VectorScale(%impulseVec, %force);
%targetObject.applyImpulse(%position, %impulseVec);
}
}
}Apply a small force from the center of the door. It doesn't even have to be enough to push the player clear, just enough to get them moving. Then their collision detection should kick in.
Edit: A few more script changes.
Edit again: It occurs to me that a trigger might be better than that radius script, since a sphere is probably not the ideal detection region in this case. It would make more sense I think to itterate through all objects in the trigger, and push them out.
#3
05/02/2005 (2:02 am)
Just realized, I'm assuming you're simply trying to prevent your player from winding up "in" the door when it closes. If you're looking to preform some other function, like kill the player if a door closes on them, then I'd again suggest a trigger around the door. You still won't get a door::onCollision event, but you can check for players in the trigger at closing time.
#4
One of the bad side effects of "pushing" the player was discovered recently when one of my testers discovered he could actually back in to a locked door and the pushback caused him to go thru the geometry so no key was required. The other bad side effect was the push back would move the player thru the diff geometry and they would fall thru the world.
I'll try the micromove method to push the player just enough to trigger the collsions and the trigger method to see which is best.
Now if a boulder falls on my player no damage as long as the player doesn't move. Can I have the bolder derive from player to trigger such an event?
05/02/2005 (4:22 am)
Thanks for the reply. The easiest method seems to be the trigger and I will test that today.One of the bad side effects of "pushing" the player was discovered recently when one of my testers discovered he could actually back in to a locked door and the pushback caused him to go thru the geometry so no key was required. The other bad side effect was the push back would move the player thru the diff geometry and they would fall thru the world.
I'll try the micromove method to push the player just enough to trigger the collsions and the trigger method to see which is best.
Now if a boulder falls on my player no damage as long as the player doesn't move. Can I have the bolder derive from player to trigger such an event?
Torque Owner EddieRay