Game Development Community

Shape start out facing camera

by Steve Self · in Torque Game Engine · 12/25/2005 (1:19 am) · 1 replies

I'm just getting into torquescript and need a LOT of help with this code! It is probably all wrong and if anyone can help me, I'd appreciate it a lot! Anyway, what it is SUPPOSED to do is make it so when you get a money object, "moneyDispOne" is created and it faces the camera on the Z axis and always stays right above the player's head. Here it is so far:

EDIT: I got it to *sort of* work, but I still need some help:
datablock StaticShapeData(moneyDispOne) // creating the rotating shape datablock...
{
   category = "Money";
   emap = true;
   shapeFile = "~/data/shapes/money/onedollar.dts";
};

function moneyDispOne::onAdd(%this,%obj)
{
    moneyDispPosition();
}

function moneyDispPosition()
{
    %pos = LocalClientConnection.camera.getPosition(); // Help! I need a function that gets the position of the orbiting camera. This seems to get the position of the observer mode camera.
    %pos2 = $moneyShapeToRotate.getTransform(); // $moneyShapeToRotate represents the object itself.
    %pos3 = LocalClientConnection.player.getTransform(); // player position

    %px = getword(%pos,0); // get camera x
    %py = getword(%pos,1); // get camera y

    %p3x = getword(%pos3,0); // get player x
    %p3y = getword(%pos3,1); // get player y
    %p3z = getword(%pos3,2)+2.5; // get player z

    %r2x = 0; // x rot
    %r2y = 0; // y rot
    %r2z = 1; // z rot
    %r2r = mAtan(-(%p2y-%py)/(%p2x-%px)); // get object rotation

    %posrot = %p3x SPC %p3y SPC %p3z SPC %r2x SPC %r2y SPC %r2z SPC %r2r; // put it all together

    $moneyShapeToRotate.setTransform(%posrot); //transformation
    schedule(50,0,"moneyDispPosition"); //do it again!
}

also, in another script:

function Money1::onCollision( %this, %obj, %col )
{
    $money = $money + 1;
    %temprotate = new StaticShape()
    {
        datablock = "moneyDispOne";
    };
    $moneyShapeToRotate = %temprotate;
    if ($moneygoing == false) {
        moneyIncrease(); }
    %obj.delete();
}

Problem is, I don't know what funtion to use to get the orbiting camera's position. Also, the object has very jerkey movements because I used 50 ms for the schedule time (I don't want to go too low). Any way to do this without such jerkiness?

If you can help, I'd be grateful. :)

#1
02/14/2006 (11:39 am)
Steve - What exactly are you trying to get to happen here?

Are you trying to get it to stay over the players head and always face it like a billboard?

That's what I got from your explination...

You could export the money object as a billboard (see the documentation for whatever exporter you used) and then export the character with an additional node, that you can use for mounting (again see the exporter docs)... and then mount the billboarded money object to the players mount node.

That should work. :)