Author Topic: teleport to random position within a certain area [Solved]  (Read 1117 times)

I need to know how to teleport players into a flat zone at a random location
« Last Edit: April 26, 2013, 07:01:10 PM by swollow »

what do you mean by "flat zone"

I use this in Wario Ware.

Code: [Select]
function getRandomFloat( %min, %max )
{
return %min + getRandom() * ( %max - %min );
}

//getRandomVect(%vectA, %vectB);
//Returns a random vector between Vector3F %vectA and Vector3F %vectB.
//%len is an unsigned integer 0-5 for the allowed float length, defaults to two.
function getRandomVect(%vectA, %vectB)
{
%xA = getWord(%vectA, 0);
%yA = getWord(%vectA, 1);
%zA = getWord(%vectA, 2);
%xB = getWord(%vectB, 0);
%yB = getWord(%vectB, 1);
%zB = getWord(%vectB, 2);
if(%xA != %xB)
%x = getRandomFloat(%xA, %xB);
else
%x = %xA;

if(%yA != %yB)
%y = getRandomFloat(%yA, %yB);
else
%y = %xA;

if(%zA != %zB)
%z = getRandomFloat(%zA, %zB);
else
%z = %zA;
return %x SPC %y SPC %z;
}

function GameConnection::spawnInArea(%this, %cornerA, %cornerB)
{
%this.instantRespawn();
%vect = getRandomVect(%cornerA, %cornerB);
%this.player.position = %vect;
}

Needs two corners. May be a better way to do it. Depends on your usage. The last function may be unnecessary for you.
« Last Edit: April 26, 2013, 06:54:36 PM by otto-san »

thanks for the help guys ;)

what do you mean by "flat zone"
I meant the z axis is constant
« Last Edit: April 26, 2013, 07:06:51 PM by swollow »