Game Development Community

Falling Objects causeing Damage?

by Kirchgessner · in Torque 3D Professional · 12/30/2010 (9:45 am) · 8 replies

ok, here is my issue. I have a character in game, the default player, I also have a 20 ton rock. If I put the rock high in the air, and put the player under that rock, as soon as it falls onto the player it causes no damage. To add to this it also kind of just bounces off like Styrofoam.

I first thought, well the script isn't there in onCollision, so I made a script to at least Echo damage based off speed etc. Works if I'm running into stuff, or if stuff runs into me in a horizontal sense. However, any items that fall on top of me don't register with the onCollision scripting.

Anybody know of what might be going on?

Any and all help is appreciated.
Thanks

#1
12/30/2010 (12:35 pm)
The collision stuff (respectivelly _move()) is not called when you have zeroed velocity.
If you workaround this,you'll meet a new problem - objects get stuck each other.

The right way is create a new class for the rock (I believe you're using StaticShape or Item), implement a simple collision query there and use a mask swapping for the player class.Then you apply an impulse in the opposite direction,based on the rock's velocity.
I have posted a part of the solution in the useful threads.

Another one solution is to attach a trigger on the rock and apply impulses when you have a contact.But this is really bad,because you will get massive packet disagree messages and this may goof up the network.
#2
12/30/2010 (1:19 pm)
@Brian,
you talking about the players onCollision? or the rocks onCollision?
there is a difference.
use the rocks onCollision, like this:
if ( %speed >= 1 )   
   {   
     if(%col.getDataBlock().getName() $= "DefaultPlayerData")
      {
        echo("collided with PlayerData");
        %directDamage = 50;
        %position = %col.getPosition();   
        %impulse = %this.areaImpulse;   
        %fwVec = %obj.getForwardVector();   
        %impulseVec = VectorSub(%col.getWorldBoxCenter(), %position);   
        %impulseVec = VectorNormalize(%impulseVec);   
        %impulseVec = VectorScale(%impulseVec, %impulse *10); //* %fwVec   
        %impulseVec = VectorScale(%impulseVec, 0.5);   
        %col.applyImpulse(%position, %impulseVec);
        return;
      }

or even

if ( %speed >= 1 )   
   {   
       if(%col.getType() & $TypeMasks::PlayerObjectType)
        {
         %db = %col.getDataBlock();

          if(%db.getName() $= DefaultPlayerData)
          {
           echo("collided with PlayerData");
          %directDamage = 50;
   	      %force = VectorScale(%normal,100);
	      %force = VectorSub("0 0 0",%force);
	      %col.applyImpulse(%pos,%force);
          return;
         }

both should work, all my physics objects, physics debris, vehicles, and players use one or the other of these to deliver damage and to move the player on collision,
and the player can also move the objects, using a similar function.

the object's onCollision for when the object hits a player(to move/damage the player),

the player's onCollision for when the player hits an object(to move/damage the object).

do I make sense here? sometimes I don't.

if you want, I can expand more on it.
#3
12/30/2010 (9:45 pm)
Ok weird issue, deepscratch. I'm using the code you lent me. And under Scripts/server/physicsshape.cs

I added PhysicsShapeData::onCollision(...
Then added your code onto it.
And its never calling the onCollision code for any of the Physics shape objects

any ideas?
#4
12/30/2010 (11:05 pm)
because the physicsShape.cpp does not have a raycast,
so just copy the raycast from the player over to it and try again
#5
12/31/2010 (1:01 am)
kk, thanks for the reply, I'm copying the source from player, hopefully will have it running shortly.
#6
01/08/2011 (5:31 am)
I tried to add the castRay function from the player cpp to the physicsshape.cpp but I get alot of errors about some of the objects not being defined. So I went into player.h and copied the castray bool over to the physicsshape.h and recompiled.

Is that what I needed to copy?

EDIT:
Interesting occurrence whenever I have a slanted physics object and the castray function was copied. I got it copied and compiled successfully but, whenever I step on a slanted or sloped physics object in 3rd person mode a "Realistic FPS" camera vision (best way to describe it) appears. Once the head node of the player gets past the bounds of the sloped object the camera returns to normal 3rd person. All square blocks function fine.

Note: I do like the looks of how this camera appears but I have no idea why its doing what it is.
Will provide screeny if you guys want.
#7
02/07/2011 (6:34 pm)
Ye, a screeny would be cool. I'm quite interested in objects damaging on high-speed collision. Thanks.
#8
02/08/2011 (7:28 am)
Quote:I tried to add the castRay function from the player cpp to the physicsshape.cpp
As in Player::castRay? That shouldn't have anything to do with the rock colliding against the Player. This function is called when other objects (like projectiles) cast rays against the PhysicsShape object. I haven't looked at thisarea of the source yet, but depending on what PhysicsShape is derived from it should handle this already.

Quote:I added PhysicsShapeData::onCollision
This should be the right way to go, I don't know why it wouldn't be working. Of course, I really don't know anything about T3D's PhysX/abstract physics layer implementation, so it might be different from the old standard, which is to have onCollision calbacks when a moving object collides with something.

Is there a PhysicsShape::onCollision function in code? Or a PhysicsShape::queueCollision?

(I'm away from my dev comp at the moment ;P.)

Quote:Interesting occurrence whenever I have a slanted physics object and the castray function was copied.
This is because the Player::castRay function only works against aworld-aligned bounding box, as opposed to actual model geometry. So when you have PhysicsShapes using this code, and you stand on one which is slanted, your character's head is going inside the object's bounding box, and the raycast which is used to place the 3rd person camera thinks you're inside a wall, so it puts the camera exactly at the character's eye location.