Game Development Community

Different Teleporting

by Christian · in Torque Game Engine · 12/13/2006 (12:10 am) · 7 replies

I'm trying to code a different kind of teleport than the ones in the tutorials, I want to go a straight 20 feet in front. Just through looking at other code i've tried:

$player.setTransform( VectorAdd($player.position, "0 30 0") );

after setting $player = %player; in game.cs

Am I close on this, what do I need to change?

#1
12/13/2006 (12:19 am)
Try this:

Get the eye transform of the player.
Normalize the vector.
Scale the vector by 20 feet.
Do a vector sub using the players position vector and the vector that has been scaled.
Now, from the sub'ed vector, find the height position (by casting) to find a valid height.

So now, you have a valid X, Y from the subbed vector, and a valid Z from the cast.
#2
12/13/2006 (12:56 am)
Thanks for the reply, unfortunately I am not experienced enough to know how to do any of that? Is there a resource around that will teach me how to normalize, scale, sub vectors/casting, etc?
#3
12/13/2006 (1:22 am)
Math functions can be found in 'mathTypes.cc' if you have access to engine functions.

%player.getEyeTransform() to get the players eye vector

VectorNormalize(%vector) will normalize the vector (making the size 1)

VectorScale(%vector, %amount) you can scale your 1 vector by 20 (so, the vector is pointing from the eyes 20ft away)

VectorSub(%vectorA, %vectorB) (A - B) you subtract your players vector (from zero origin to player, %player.position) with this direction vector and it will give you a vector to that 20ft player position from the zero origin.

Tricky part is finding 'safe ground'. You can just start off by using: %height = getTerrainHeight(%my2DPosition) (from terrData.cc)

Finally, 'complete' the final position vector by taking the X and Y from your subtracted vector using 'getWords' function and merge it with the height.

-------------

If you want to extend this further, you have to consider more options as in, what if there is a building there, a player object, etc. Then you should look into ray casting.

Perform a cast by using this function: "%object = ContainerRayCast(%vectorStart, %vectorEnd, %mask);"

What this function does it "Check for any objects of type [MASK] that starts from 'VECTORSTART' to 'VECTOREND'". But I'm sure you can get better explanations on this in another forum post.
#4
12/13/2006 (7:14 am)
Or a simplified version something like:

%playerPos = getWords( %player.getTransform(), 0, 2 );
%player.setTransform( vectorAdd( %playerPos, "0 20 0") );

You can still do checks if your in terrain or on a player if you need to.
#5
12/13/2006 (10:40 am)
I tried this

datablock ItemData(TorqueLogoItem) // change the itemdata name to anything you like
{
category = "Items";
shapeFile = "~/data/shapes/3dtorquelogo/torque_logo.dts"; // heres the model you will use...
};

function TorqueLogoItem::onCollision(%this, %obj, %col) // use the data name here etc. function StrengthUpgrade::oncollision...
{
if(%col.getClassName() $= "Player")
{ 
echo("Teleport");
%obj.delete();

//movement

%playerPos = getWords( %player.getTransform(), 0, 2 );
%player.setTransform( vectorAdd( %playerPos, \\"0 20 0\\") ); 


}
}

it says that last line with vectorAdd is unable to find. I think it's because I didn't properly set up %player in this, not sure.
#6
12/13/2006 (10:59 am)
Try %col in place of %player, I beleive thats that collision object, if that doesnt work try %obj

just to clarify:

%playerPos = getWords( %col.getTransform(), 0, 2 );
%col.setTransform( VectorAdd( %playerPos, "0 20 0") );
#7
12/13/2006 (11:34 am)
Not sure what i'm doing wrong, i'll try to hack away at it all. Thanks for the help.