Game Development Community

T3D 1.2 - Player can shoot self with Physx enabled

by Bryce · in Torque 3D Professional · 01/19/2012 (6:59 pm) · 22 replies

Build: 1.2 Pro

Platform: Windows 7 64-bit

Target: Game.

Issues: I recently enabled PhysX in my project, and the player is able to hit himself with his own projectiles when looking down. Somehow, activating Physx must have messed with the don't-collide-with-sourceobject checks in the projectile code. Thoughts?

Steps to Repeat:
1. Launch PhysX activated game.
2. Look all the way down, to where your feet would be if they were rendered.
3. Shoot.
4. Get damaged. Cry uncontrollably.
Page «Previous 1 2
#1
01/20/2012 (9:25 am)
1.1 Beta 2?

This was a known issue of 1.2. The way the soldier's root pose is positioned you'll end firing at your knee or thigh if you look straight down. For this reason we limited the player's look angle so that the player wouldn't be able to look down and put one in their leg.

So it sounds like we may have missed a template with that change or old values may have been brought in when porting over your project. A more permanent solution is in the works though.
#2
01/20/2012 (9:33 am)
It's not a bug ... it's realism!
#3
01/20/2012 (12:44 pm)
I realistically shot myself in my invisible leg!
#4
01/20/2012 (12:52 pm)
Title edited. I meant Torque 3D 1.2 Pro!

I only started to notice it once I dropped in PhysX. I had also recently brought the look ranges back to normal. I thought the projectile source object disables their collision upon firing?
#5
01/20/2012 (12:55 pm)
You could throw in a little raycast to test for aborting prior to projectile creation.
#6
01/20/2012 (4:25 pm)
I remember hearing that the SourceObj on projectiles was supposed to stop this from happening, I've noticed this problem as well.

This also happens when walking on uneven terrain, truthfully I've noticed it happen more when moving then when staying still.
#7
03/20/2012 (9:53 pm)
Anybody have a solution to this yet?
#8
03/21/2012 (4:16 am)
Have you tried my raycast idea?

In onFire() do a 2 or 3 unit raycast before creating the bullet and if targetHit == sourceObj abort the whole thing.

It could also help to make a smaller boundsBox for the player.
#9
03/21/2012 (5:14 am)
I did try that, but it still causes problems when the player is moving and firing at the same time, or firing from a railing. Even when crouched or prone, the raycast hits the player's box and Houston continues to have problems.
#10
04/02/2012 (8:49 am)
A fix!

(All changes in projectile.cpp.)
In Projectile::simulate:

Right before the line

if ( hit )

Add

bool sameHit = false;
   if (rInfo.object)
   {
	   if (mSourceObject == rInfo.object)
	   {
		   hit = false;
		   sameHit = true;
	   }
   }

And at the end of this function, replace

mCurrDeltaBase = newPosition;
   mCurrBackDelta = mCurrPosition - newPosition;
   mCurrPosition = newPosition;

   MatrixF xform( true );
   xform.setColumn( 3, mCurrPosition );
   setTransform( xform );

With...

mCurrDeltaBase = newPosition;
   mCurrBackDelta = mCurrPosition - newPosition;

   if (sameHit)
	   mCurrBackDelta *= 0.1;
   if (sameHit)
	  mCurrPosition = mCurrPosition - mCurrBackDelta;
   else
      mCurrPosition = newPosition;

   MatrixF xform( true );
   xform.setColumn( 3, mCurrPosition );
   setTransform( xform );

And we're in business. Projectiles no longer collide with their sourceObject.
#11
01/29/2013 (7:00 pm)
i get an error trying this sameHit undeclared identifier
#12
01/29/2013 (7:57 pm)
In the second code block I posted:

bool sameHit = false;

That error shouldn't be happening if this line of code is there. Make sure that's properly in place.
#13
01/29/2013 (8:29 pm)
yup your right i put it after if ( hit ) and not before it, works great thanks.
#14
04/14/2013 (7:20 am)
Hei there, sorry to vamp another thread here. I just tried out this solution on Torque 3D MIT 2.0 and some how it does not work out. I have done this:
bool hit = false;

   if ( mPhysicsWorld )
      hit = mPhysicsWorld->castRay( oldPosition, newPosition, &rInfo, Point3F( newPosition - oldPosition) * mDataBlock->impactForce );            
   else 
      hit = getContainer()->castRay(oldPosition, newPosition, csmDynamicCollisionMask | csmStaticCollisionMask, &rInfo);
   // --------- changes here begin
   bool sameHit = false;  
     if (rInfo.object)  
     {  
         if (mSourceObject == rInfo.object)  
         {  
             hit = false;  
             sameHit = true;  
         }  
     }
   // --------- changes here end
   if ( hit )
   {
      // make sure the client knows to bounce
      if ( isServerObject() && ( rInfo.object->getTypeMask() & csmStaticCollisionMask ) == 0 )
         setMaskBits( BounceMask );

And here

if (sameHit)  
       mCurrBackDelta *= 0.1;  
  if (sameHit)  
      mCurrPosition = mCurrPosition - mCurrBackDelta;  
  else  
      mCurrPosition = newPosition;  
  
   MatrixF xform( true );  
   xform.setColumn( 3, mCurrPosition );  
   setTransform( xform ); 

   //mCurrDeltaBase = newPosition;
   //mCurrBackDelta = mCurrPosition - newPosition;
   //mCurrPosition = newPosition;

   //MatrixF xform( true );
   //xform.setColumn( 3, mCurrPosition );
   //setTransform( xform );

So what am I missing here? I and my bots are still shooting their toes off at slopes etc.... I did a clean solution, build the project anew in Visual Studio C++ 2010 and generated the project by running the projectBatch in the Torsion project folder before testing this solution fix and still no result.

Any help or suggestions would be appreciated...
#15
04/14/2013 (2:23 pm)
Found another fix for this, thought that I would like to share this fix so here it is.

The eyeOffset X Y Z in the weapon(bow lurker etc.) needs to be tweaked so it does not collide with the boundary boxes. By setting the Y to 1 and z to -0.35 I shoot from outside the boundary box and then the minLookAngle(look up) and maxLookAngle(look down) wont be an issue anymore.

You gotta tweak it so the missile(projectile) do not shoot your self in the foot when shooting down at the enemy from a hill etc. Also the maxLookAngle was the biggest problem to tweak as a value lower than -0.15 would mean accidentally suicide by any bot or player and that meant no chance of firing at enemy from high ground.

this setting work for me with a dummy weapon like blank.dts
datablocks/weapons/YourNameForWeapon.cs
.
.
eyeOffset = "0 1 -0.35";
.
.
art/datablock/YourPreferedDefaultPlayer.cs
.
.
minLookAngle = "-0.9";
maxLookAngle = "0.6";
.
.
.
boundingBox = "1.0 1.0 2.5";//width depth height
.
.

Hope someone can use it if they encounter the same issue.

Cheers all Torque dudes :o)

Le Ubersome Dwarf King

Because you gotta script if you wanna ship ;o)




#16
04/15/2013 (1:50 am)
The normal raycast allows a U32 to be passed in with the objectTypes that you want the Ray to collide with.

One of the problems with PhysX is that there is no in built way to exclude an object or object types from its raycasts. Its rays hit every object type that is registered with it

#17
03/04/2014 (6:58 am)
Another Issue with Physics and shooting things..

Triggers have become invisible walls/shields protecting those inside
from getting shot *chuckle*, altho you can still shoot out.
#18
03/04/2014 (3:41 pm)
Is this still currently happening? I tried placing a box inside a trigger and can still shoot it? Is this only happening with actual player objects inside a trigger?
#19
03/04/2014 (11:50 pm)
Frankly I do not use PhysX anymore. I simply just opt for the solution I mentioned above last year or control which objectTypes the raycast should collide with(I am all into the AFX Addon/Enginefor T3D MIT so that is why).

PhysX cost me too much pain and development time so he got ripped out of the project as I ported my work into a AFX for Torque 3D MIT instead... Actually it was just Torque 3D 1.2 to begin with and then later for Torque 3D MIT version 2.0(which is almost the same).

I can't say I regret it as I feel relieved and the game Noble Games Production is producing at this time do not really need PhysX.

Quote:
Triggers have become invisible walls/shields protecting those inside
from getting shot *chuckle*, altho you can still shoot out.

I do not recall having such issues with Torque 3D 1.2 with PhysX enabled back then. Pretty odd. Another reason why PhysX got fired for this current project.
#20
03/05/2014 (12:25 am)
This is not a physx problem, it just so happens it is the enabled physics plugin at the time. I'm guessing the bullet physics plugin wasn't around back than.

Quote:
One of the problems with PhysX is that there is no in built way to exclude an object or object types from its raycasts. Its rays hit every object type that is registered with it

This is just not true at all.
Page «Previous 1 2