[Code Snippet]Facing Character to X , Y

10/19/2009 23:09 Bl@ze!#1
Hey community,

i want to share some code snippets to you because NCsoft changed a little bit in Aion and now i want to share a new Facting to X Y method. ;)

Thanks to PharmerPhale for some help. :)

C# Code

Code:
        private double RotNeeded(float X, float Y)
        {

            double faceAngle = Math.Atan2(Y - Player.GetPlayerY(), X - Player.GetPlayerX());
            faceAngle = faceAngle * 180 / Math.PI;
            faceAngle -= 90;

            if (faceAngle > 180)
            {
                faceAngle -= 360;
            }

            faceAngle -= 180;

            if (faceAngle < -180 && faceAngle > -360)
            {
                faceAngle += 360;
            }

            return faceAngle;

        }
This method gives you the Player Rotation back which the character needs for the new X and Y coordinate. If you want to use it you need to insert your own GetPlayerRotation and your own GetPlayerX and Y. If you dont know how to use the math namespace, try looking at msdn. :)

C++ Code

Code:
double aPlayer::rotationNeed(float X, float Y)
{
	double faceAngle = atan2(Y - pCoordY(), X - pCoordX());
	faceAngle = faceAngle * 180 / 3.14159265;
	faceAngle -= 90;

	if (faceAngle > 180)
		faceAngle -= 360;

	faceAngle -= 180;

	if (faceAngle < -180 && faceAngle > -360)
		faceAngle += 360;

	return faceAngle;
}
And thats my C++ version of this. You have to include <math.h> and you have to replace my pCoordX() pCoordY() and pRotation() then it should work for you. :)

I hope I can help some coders. :)

So long,

Unknw0n0x
10/26/2009 10:00 mel andru#2
Kann es sein dass der Ausdruck:
Code:
 if (faceAngle < -180 && faceAngle > -360)
Nicht Wahr werden kann ?

Quote:
Logisches UND &&

Das Ergebnis des Ausdrucks ist 1, wenn beide Operanden ungleich 0 sind, andernfalls 0. Im Unterschied zum & wird der Ausdruck streng von links nach rechts ausgewertet. Wenn der erste Operand bereits 0 ergibt, wird der zweite Operand nicht mehr ausgewertet und der Ausdruck liefert in jedem Fall den Wert 0. Nur wenn der erste Operand 1 ergibt, wird der zweite Operand ausgewertet. Der && Operator ist ein Sequenzpunkt: Alle Nebenwirkungen des linken Operanden müssen bewertet worden sein, bevor die Nebenwirkungen des rechten Operanden ausgewertet werden.

Das Resultat des Ausdrucks ist vom Typ int .
faceAngle < -180 && faceAngle > -360

So wie ich das verstehe kann der Winkel doch nicht kleiner -180 UND größer -360 sein oder ?
10/26/2009 19:10 _revo#3
Quote:
Originally Posted by mel andru View Post
Kann es sein dass der Ausdruck:
Code:
 if (faceAngle < -180 && faceAngle > -360)
Nicht Wahr werden kann ?



faceAngle < -180 && faceAngle > -360

So wie ich das verstehe kann der Winkel doch nicht kleiner -180 UND größer -360 sein oder ?
ynot?
angle is just between -180° and -360°
10/26/2009 22:59 mel andru#4
Well thanks for Info.
Another Question (Sorry for Bothering yours)

He wrote that i need "pRotation()" well i got this function but cant find it in his code something missing ?

I consoled out the function and getRot() but i dont get it.

Im really confused about this strange Compass in Aion having -90 N / -135 NE
/ -180 E / 135 SE / 90 S / 45 SW / 0 W / -45 NW ....

I used to write functions for Waypoint Navigation for Lotro so the Basics with Arctan, rad, degree and relation between the degree Value of Arctan isnt unknown but i cant handle it in Aion this Compass is really confusing me.

Im trying now since almoast a week to get this facetarget working im almoast running mad.

Any Help would be appriciated, like do i have to and how change the Compass to E = 0 or N = 0

thanks in Advance
10/27/2009 11:18 Bl@ze!#5
pRotation = a function which returns your rotation in a double value you have to replace it with your own function ;)