Author Topic: Getting and setting a player's position?  (Read 1036 times)

How do you get and set a player's position? I've tried using
Code: [Select]

function serverCmdwhereami(%client)
{
    messageClient(%client, '',"\c6You are at" @ findClientbyName(%client).player.getPosition() @ "\c6.");
}
, but it doesn't return any syntax errors, and it just shows up with "You are at.".
Am I doing something wrong?

You were doing it the correct way, the only problem is that you were doing findClientByName(%client).

When you have a serverCmd, the first argument is always a client object, so there's no need to use that function.

Instead, you would just do %client.player.getPosition().


To set position, typically it's good practice to use %player.setTransform(%pos SPC %rot);, but just setting %player.position works.
« Last Edit: February 16, 2014, 09:42:53 AM by otto-san »

Also, how would you set the player's position? I tried %client.player.setPosition("position"), but apparently there's no setPosition. Ideas?

Also, how would you set the player's position? I tried %client.player.setPosition("position"), but apparently there's no setPosition. Ideas?
To set position, typically it's good practice to use %player.setTransform(%pos SPC %rot);, but just setting %player.position works.

Wow, you posted one second before Otto-san edited that last bit in (or at least I presume that's what he did).


But yeah, use setPosition, %pos is a 3d vector coodinate as im sure you're aware, and %rot is a axis angle. If you want to rotate the player, its probably best if you use the eulerToAxis and axisToEuler functions posted somewhere in this forum. If you dont include %rot, then the players current rotation will be used, thus it wont rotate the player.

Wow, you posted one second before Otto-san edited that last bit in (or at least I presume that's what he did).


But yeah, use setPosition, %pos is a 3d vector coodinate as im sure you're aware, and %rot is a axis angle. If you want to rotate the player, its probably best if you use the eulerToAxis and axisToEuler functions posted somewhere in this forum. If you dont include %rot, then the players current rotation will be used, thus it wont rotate the player.
%player.setPosition(); does not exist..

%player.setPosition(); does not exist..
use %player.settransform()

Ok, so would it be like this?
Code: [Select]
function serverCmdteleport(%client, %target, %pos, %rot)
{
    %target.setTransform(%pos SPC %rot);
}

Ok, so would it be like this?
Code: [Select]
function serverCmdteleport(%client, %target, %pos, %rot)
{
    %target.setTransform(%pos SPC %rot);
}
No.

The correct format (I don't feel like explaining this)


function serverCmdTeleport(%client, %target, %posA, %posB, %posC, %rotA, %rotD, %rotC, %rotD)
{
   %rot = %rotA SPC %rotB SPC %rotC SPC %rotD;
   %pos = %posA SPC %posB SPC %posC;
   if(!isObject(%target=findClientByName(%target)) //Does the target's name exist on the server?
      return;
   if(!isObject(%pl=%target.player)) //Does the player exist?
      return;
    %pl.setTransform(%pos SPC %rot);
   //Example: %target.setTransform("0 0 0" SPC "1 0 0 0");
   // /TelePort Vis 0 0 0 1 0 0 0
}

Code: [Select]
function Player::MoveTo(%this, %pos)
{
    %rot = getWords(%this.getTransform(), 3);
    %pos = getWords(%pos, 0, 2);
    if(getWordCount(%pos) == 3)
        %this.setTransform(%pos SPC %rot);
}

To get a player's position, use Player::getPosition().
« Last Edit: February 16, 2014, 02:05:02 PM by $trinick »