Game Development Community

Plane flyby

by John Tear · in Torque Game Engine · 08/26/2007 (5:01 pm) · 5 replies

Hi

I am a noob to Torque and have only been playing around for a few days. I thought it would be nice to write a little bit of script to make a plane flyby the scene so I started with the following script:

//-----------------------------------------------------------------------------
// Basic flyby
//-----------------------------------------------------------------------------


datablock ItemData(BiPlane){
shapeFile = "~/data/shapes/biplane/biplane.dts";
};


function insertPlane(){
%biplane = new Item(){
datablock = BiPlane;
};
%biplane.setTransform("9 -342 75 0 0 0 0");
MissionCleanup.add(%biplane);
movePlane(%biplane, %dist);
}

function movePlane(%biplane, %dist){
%transform = %biplane.getTransform();
%lx = getWord(%transform, 0);
%ly = getWord(%transform, 1);
%lz = getWord(%transform, 2);
%ly -= %dist;
%biplane.setTransform(%lx SPC %ly SPC %lz SPC "0 0 0 0");

Timer.setText("yPos:"@%ly);
schedule(32, 0, movePlane, %biplane, 1);
}


The problem I have is that the plane sinks into the ground! :D - I guess this has something to do with gravity etc... Any pointers would be much appreciated!

Thanks

JT

About the author

Recent Threads

  • Mission/Terrain Editor

  • #1
    08/27/2007 (4:51 am)
    Item has gravity - also your code will be prone for jerky updates and other weird behaviour.

    Try looking at some of the older "move shape along path" ressources that exist on this site.
    #2
    08/27/2007 (1:34 pm)
    Thanks Thomas.

    I changed some of the script to:

    %biplane.setTransform(%lx SPC %ly SPC "75 0 0 0 0");

    Just as an experiment to keep the Z coord consistent and you are correct it was very jerky, almost as if the callbacks were not consistent in time - is this correct? (I am supposing that it cannot be guaranteed whilst a load of rendering is going on - I am also brand spanking new to 3D engines so this is a guess!)

    Is there any general guidelines for using the schedule function? More importantly when should I NOT use it - this is obviously a good example.

    Anyway thanks for the pointer - I'll check out the resources you suggested.

    JT
    #3
    08/27/2007 (2:25 pm)
    You don't want to use schedule() for anything you want to happen more often than once or twice per second, imo. so ie, things that you want to happen every frame shouldn't be schedules.

    part of the reason is the limited maximum speed of windows timers,
    part is the unavoidable Aliasing between rendering and the schedules,
    and the main thing is it's just the wrong way to do it.

    try looking for that resource the man of ice suggested.
    #4
    08/27/2007 (3:06 pm)
    Thanks

    I will check out the resource when I get a bit of time. As long as I find out the wrong way to do things early on I should be ok.

    For the record I'm using Mac OSX NOT Windows :P But I understand what you are saying.

    Just had to add: I had took a look at Doppelganger... one word... Awesome!
    #5
    08/27/2007 (11:48 pm)
    Problem with script schedules is, that they are not guaranteed to run at the specified time. And 32 milliseconds is WAY out of script schedule capabilities.

    So you get jerky movement as a result.

    Only way to get 32 ms updates consistently is to use the engine code. Internal "clock" = tick is set to 32 ms.