Game Development Community

Gravity?

by Temasek Polytechnic · in Torque Game Engine · 05/31/2006 (8:23 pm) · 4 replies

Can i add gravity to a StaticShape object?

I tried to add mass = 100; and created the object in the air, but it did not fall to the ground.

#1
05/31/2006 (10:22 pm)
Nope. StaticShapes don't have any physics code... they're static =P. Items are the most minimal default class that has basic gravity physics.
#2
05/31/2006 (11:12 pm)
Oh.

So is there like anyway to program it in such a way that it can be created directly on the ground?
#3
05/31/2006 (11:18 pm)
Search is your friend, here you go :)
#4
05/31/2006 (11:22 pm)
@Temasek,

Hi. Here are a few functions you might find useful. They are from the kit that comes with my book GPGT. If you have the book already, you should check out the disk that comes with it. I put lots of goodies on it. If not, well hopefully you'll think about it. Regardless, here is the code, use it in good health:


// Note: This function will not move TSStatic() objects.
//       Their positions must be set once and only once,
//       on construction.  Use CalculateObjectDropPosition() instead.
//

function DropObject( %object , %offsetVector ) 
{
   %mask	= 
      $TypeMasks::TerrainObjectType			|
      $TypeMasks::InteriorObjectType			|
      $TypeMasks::StaticShapeObjectType		|
      $TypeMasks::PlayerObjectType			|
      $TypeMasks::ItemObjectType				|
      $TypeMasks::VehicleObjectType			|
      $TypeMasks::VehicleBlockerObjectType	|
      $TypeMasks::StaticTSObjectType;

   %oldTransform = %object.getTransform();
   %oldPosition  = getWords(%oldTransform, 0, 2);
   %subTerrain   = getWords(%oldTransform, 0, 1) @ " -1";

   %newPosition = containerRayCast( %oldPosition , %subTerrain , %mask , 0 );

   	//echo("Ray hit => " @ %newPosition);

   %newPosition = getWords(%newPosition, 1 , 3);
   
   // Add user specified offset
   if("" !$= %offsetVector) 
   {
      %newPosition = VectorAdd(%newPosition, %offsetVector);
   }

   %newTransform = %newPosition SPC getWords( %oldTransform , 3 , 6 );

   //echo("\c2" SPC %object.getName() @ " => oldTransform = " @ %oldTransform);
   //echo("\c5" SPC %object.getName() @ " => newTransform = " @ %newTransform);


   // Update this object's position.
   //
   // Q: Why not just do a %obj.position = "x y z"; ??
   // A: This will move the object, but only setTransform()
   //    will correctly update the location/orientation of
   //    the object's bounding/world box.  
   //

   %object.setTransform( %newTransform );

}

function DropObjectFromMarker( %object , %marker , %offsetVector ) {
   %object.setTransform(%marker.getTransform());
   DropObject( %object, %offsetVector ) ;
}


// Note: This function is used to calculate the final position as if a
//       drop were done.

function CalculateObjectDropPosition( %oldPosition , %offsetVector ) {
   %mask	= 
      $TypeMasks::TerrainObjectType			|
      $TypeMasks::InteriorObjectType			|
      $TypeMasks::StaticShapeObjectType		|
      $TypeMasks::PlayerObjectType			|
      $TypeMasks::ItemObjectType				|
      $TypeMasks::VehicleObjectType			|
      $TypeMasks::VehicleBlockerObjectType	|
      $TypeMasks::StaticTSObjectType;

   %subTerrain  = getWords(%oldPosition, 0, 1) @ " -1";

   %newPosition = containerRayCast( %oldPosition , %subTerrain , %mask , 0 );

   %newPosition = getWords(%newPosition, 1 , 3);

   // Add user specified offset
   if("" !$= %offsetVector) {
      %newPosition = VectorAdd(%newPosition, %offsetVector);
   }

   return %newPosition;
}


www.hallofworlds.com/how.ico Hall Of Worlds - For Gamers
EdM|GPGT