Author Topic: Grid to angle?  (Read 615 times)

How would I turn a normalized vector into an angle? I am trying to rotate players using eulertoaxis() and found out that doing
setTransform(%obj.getposition() SPC Eulertoaxis("0 0" SPC %rot)) where rot seems to be 360 degree based. (0 is north, 90 is west, 180 is south, 270 is east, 360 is north again)
What I am trying to do is make players rotate on their Z axis to face a location (lets say a brick). I could easily use vectorsub for projectiles but that doesn't seem to work with what I am trying to do with players. help?

So you want the angle in radians, not degrees?

Players only have one axis of rotation, unless they're tumbling.

So you want the angle in radians, not degrees?
i guess. i want to convert the sort of grid based thing into a 360 based thing

example. the player is standing at that point. I want to make him turn on his Z to face 0,0.
setTransform(%obj.getposition() SPC Eulertoaxis("0 0" SPC ?))
i need to figure out the ? variable so he faces 0,0

You have to do some trig

Here's enough to get you started
%dif = vectorSub(%pos1,%pos2);
%rad = mATan(getWord(%dif,1),getWord(%dif,0));
%degrees = mRadToDeg(%rad) + %quadrantCompensation;

You have to do some trig

Here's enough to get you started
%dif = vectorSub(%pos1,%pos2);
%rad = mATan(getWord(%dif,1),getWord(%dif,0));
%degrees = mRadToDeg(%rad) + %quadrantCompensation;

forgot to define %quadrantcompensation?


I really have no idea why this solution hasn't already come up, but...

Code: (Code that turns an %obj to face a given %targ) [Select]
function turnTo(%obj, %targ)
{
   %pos = %obj.getPosition();
   %diff = vectorSub(%targ.getPosition(), %pos);
   %ang = mAtan(getWord(%diff, 0), getWord(%diff, 1));
   %obj.setTransform(%pos@" 0 0 1 "@%ang);
}