Author Topic: Rotating %obj Relative to the Direction it is Facing  (Read 512 times)

I want to make my player turn, for example, 90° to the left. How do I do so?



Very useful...

Sounds like you're being sarcastic. It's exactly what you need.

do that %eulerrot thing, set a variable for each word, add the amount you want to increase by to each word that applies, eulerToAxis(%x SPC %y SPC %z) will be the new rotation

do that %eulerrot thing, set a variable for each word, add the amount you want to increase by to each word that applies, eulerToAxis(%x SPC %y SPC %z) will be the new rotation
I am trying to take the direction my player is facing and rotate it 90 degrees to the left then setTransform to that new direction. Is that what you're explaining how to do?

Here is a command I made a long time ago that spins the player in a circle from the way they are already facing using the axisToEuler and eulerToAxis functions. Note the fact I add 180 onto the angle on line 11 (%deg = ...) - this was to make my angle go from 1 to 360, when usually it's -179 to 180.

Try playing with the numbers a bit to see how it works and then remove the loop if you want it to be instant.

Code: [Select]
function serverCmdPiderman(%cl)
{
%pl = %cl.player;

if(!isObject(%pl))
return;

%pl.spawnExplosion(deathProjectile,1);

%rot = getWords(%pl.getTransform(),3,6);
%deg = getWord(axisToEuler(%rot),2) + 180;
%pos = %pl.getPosition();

for(%i = 0; %i < 360; %i++)
{
%deg += 1;

if(%deg >= 360)
%deg -= 360;

%new = eulerToAxis("0 0 " @ %deg - 180);
%pl.schedule(%i * 0.5,setTransform,%pos SPC %new);
}

%cl.schedule(%i * 0.5,loadAvatar,"Add-Ons/Script_Piderman/piderman.cs");
}

(wow I never thought this would have a use)