Game Development Community

Make a model fly across the zone and crash into the terrain

by Jeff Yaskus · in General Discussion · 02/04/2011 (6:49 pm) · 6 replies

I'm trying to add a plane model to my level and script it crashing into the terrain.

But I'm not sure how to start -- I tried adding it as a static mesh and moving it with setTransform(), but although the command shows the location change the model never moves.

Do I need to create a model based of DefaultPlayer -- for it to be able to move ? If so, how do I keep it from falling out of the sky ?

Would appreciate any suggestions or ideas on how this might be done --

NOTE: I dont need to fly it manually, just control its flight via a script and have it crash ...

#1
02/04/2011 (9:02 pm)
tried to use DefaultPlayer as a basis to spawn the plane, but it just falls to the ground.

Isn't there an easy way to just put an object in the air ... and move it via script?

Or do I need to research building the entire FlyingVehicle structure for T3D ?? Seems a bit over-kill ...
#2
02/04/2011 (9:30 pm)
I'd make two planes models (dae or dts), one that animates flying/crashing, and one that's static and crashed. Should be easy enough to animate it with a bone or two. Might even be able to use paths?

Do a little hide/unhide action at the right time and toss in a ton of large particles to hide the ol' switch-a-roo on impact. The player would never know the difference.
#3
02/04/2011 (10:10 pm)
You could also make it a 'projectile' and then it will definitely have some effects hardcoded....?? Explosions, debris, etc.....I feel one of the 'cooler' stock objects in Torque is Damage. We had vehicles in the Combat Starter Kit that took Damage and exploded when they entered the 'Destroyed' state of the object.

Wouldn't need a 'path', it could be affected by gravity or not...seems like a lot of potential there...

I think you might first need to explain exactly the purpose and you might get some coding 'tips' tailored for the effect.

Try looking into taking Damage with Impact with ground; you should be able to hook into one of the 'scripted' processes, Damage again I say; it's one of the cooler Torque 'processes'.
#4
02/05/2011 (2:27 am)
Rex, thanks that is a great idea.

I gave it a shot and works surprisingly well -- However, the plane just fly's right on through the terrain and keeps going until the duration expires. Is there a way to enable collisions on it? So it stops and explodes when it hits the terrain?

Here is the datablock and function to fire it ... which I added to scripts/server/proj_plane.cs

datablock ProjectileData(PlaneProjectile : RocketLauncherProjectile)
{
   projectileShapeName = "art/shapes/plane/Mooney_flying.dts";

   muzzleVelocity = 25; // 5000ms / 250m/s = 2s
   velInheritFactor = 0.3;

   armingDelay = 0;
   lifetime = 5000; //(500m / 100m/s = 5000ms)
   fadeDelay = 4500;
};

function LaunchPlane()  
{  
      echo("Launching plane ...");
      
      // starting location
      %start_pos = "-600 500 300"; // xyz 
      %vec = "6 -5 -1 0";


      %muzzleVelocity = VectorScale(%vec, 25);
      
      // Create the projectile object
      %p = new (Projectile)()
      {
         dataBlock = "PlaneProjectile";
         initialVelocity = %muzzleVelocity;
         initialPosition = %start_pos;
      };
    
      MissionCleanup.add(%p);
      echo("("@%p@")... Plane Launched at "@ %p.getTransform());
}
#5
02/05/2011 (6:51 am)
Does the model have a collision mesh in it?
#6
02/06/2011 (12:18 pm)
Yes, I found the problem was WHERE it was hitting the terrain.

At first it was hitting a large rock (placed using the forest editor) ... which appeared not to trigger a collision. And it would just pass right through it.

I changed its trajectory so so it collided directly with the ground and it explodes nicely, leaving behind a big black mark.

... then figured out a way to spawn in the "crashed" model of the plane and it looks like an actual crash now.