Game Development Community

Rescue me?

by Dreamer · in Torque Game Engine · 04/22/2005 (2:47 pm) · 5 replies

I've got a few spawn points that are oh lets say roughly 50 to 100 above the terrain, I found a tutorial that allows me to spawn on the ground right directly below the spawn point (this way I don't fall to my death).

I am running into an issue though where everyonce in a while I will spawn slightly inside of the terrain, thus causing me to slowly fall into oblivion.

When this happens I would like to just deposit the player safely and automagically back onto the terrain.

The problem? I can't just check the z value of the player since my terrain is extremely hilly.

I need to find a way to check and see if something is either below the players feet currently or will be pretty soon.

Any suggestions?

FYI this is the code that I am using to return the terrain level, I have even tried adjusting the z value up by 5.

function getTerrainLevel(%pos,%rad)
{
   while(%retries < 500)
   {
      %x = getWord(%pos, 0) + mFloor(getRandom(%rad * 2) - %rad);
      %y = getWord(%pos, 1) + mFloor(getRandom(%rad * 2) - %rad);
      %z = getWord(%pos, 2) + mFloor(getRandom(%rad * 2) - %rad);
      
      %start       = %x @ " " @ %y @ " 5000";
      %end       = %x @ " " @ %y @ " -1";
      %ground    = containerRayCast(%start, %end, $TypeMasks::TerrainObjectType, 0);
      %z       = getWord(%ground, 3);

      error ("Spawn Position   : " @ %x SPC %y);
      error ("Ground Level     : " @ %z);

      %z += 5;
      
      %position = %x @ " " @ %y @ " " @ %z;
      
      %mask = ($TypeMasks::VehicleObjectType |
         $TypeMasks::MoveableObjectType |
         $TypeMasks::StaticShapeObjectType |
         $TypeMasks::ForceFieldObjectType |
         $TypeMasks::InteriorObjectType |
         $TypeMasks::ItemObjectType);

      if (ContainerBoxEmpty(%mask,%position,3.5))
      {
         error ("Spawn Position Is Good");
         return %position;
      }
      else
         %retries++;
   }
   return "0 0 300 1 0 0 0";
}

#1
04/22/2005 (3:32 pm)
Have you tried adjusting z by +10-20? If terrain is very hilly, +5 isn't much leeway.

Can you rayCast from under the terrain?
If so, maybe run a check 2 seconds after the spawn and adjust player position if necessary.
#2
04/22/2005 (3:41 pm)
Raycasts under the terrain do not appear to work, setting z to 10 does, but then my player lands with a hard thump, which really wasn't my intention, I'ld like them to have as smooth a landing as possible on all surfaces.
#3
04/22/2005 (3:44 pm)
Dreamer,

Have you tried getTerrainHeight?
%thisX = getWord(%pos, 0);
      %thisY = getWord(%pos, 1);
      %point = %thisX SPC %thisY;
      %thisZ = getTerrainHeight(%point);
      %point = %point SPC %thisZ SPC "1 0 0 0";
Thanks.

Edit: added rotation info.
#4
04/22/2005 (3:58 pm)
Ohh thats a nice looking solution I'll give it a shot.
#5
04/22/2005 (4:04 pm)
Hey that works great!, I spawn under dts objects once in a while, but I think I can fix that. Thanx!