Help: How to face a position? menu

Shout-Out

User Tag List

Results 1 to 15 of 15
  1. #1
    mskc33's Avatar Member
    Reputation
    1
    Join Date
    Nov 2012
    Posts
    28
    Thanks G/R
    1/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help: How to face a position?

    Hey,
    I'm currently learning memory editing and now im trying to face a waypoint which i have the position of.
    This is my code:

    Code:
    Vector2 playerLocation = new Vector2(getPlayer().getLocation().X, getPlayer().getLocation().Y);
    Vector2 currentWaypoint = Waypoints[wpWalkIndex];
    float playerRotation = (float)(getPlayer().getRotation() * 180 / Math.PI);
    
    Vector2 difVector = new Vector2(playerLocation.X - currentWaypoint.X, playerLocation.Y - currentWaypoint.Y);
    double tRotation = Math.Atan2(difVector.Y, difVector.X) + 180;
    
    tRotation = tRotation - playerRotation;
    Magic.WriteFloat(LocalPlayer.BaseAddress + (uint)Pointers.WowObject.RotationOffset, (float)tRotation);
    But my toon just starts spinning around,or walks in the complete wrong direction, therefore my calculation must be wrong.
    Can someone point me to the right direction?

    Help: How to face a position?
  2. #2
    DarkLinux's Avatar Former Staff
    CoreCoins Purchaser Authenticator enabled
    Reputation
    1627
    Join Date
    May 2010
    Posts
    1,846
    Thanks G/R
    193/539
    Trade Feedback
    16 (100%)
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    I would use Click To Move,and let it do all the math for you... Or go and see how CTM sets the face direction.

  3. #3
    Jadd's Avatar 🐸 Premium Seller
    Reputation
    1515
    Join Date
    May 2008
    Posts
    2,433
    Thanks G/R
    81/336
    Trade Feedback
    1 (100%)
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Pretty simple stuff. The math you're looking for is atan2( loc2.y - loc1.y, loc2.x - loc1.x ).

    Code:
    #define M_PI 3.14159265358979323846
    #define M_PI_F float(M_PI)
    
    ...
    
    	/// <summary>
    	/// Gets a linear angle between two points.
    	/// </summary>
    	float GetLinearAngle( const CVector2 &loc1, const CVector2 &loc2 )
    	{
    		CVector2 diff = loc2 - loc1;
    		float fAngle = atan2( diff.y, diff.x );
    		return NormalizeAngle( fAngle );
    	}
    
    	/// <summary>
    	/// Normalizes an angle to be within [0; 2 x PI]
    	/// </summary>
    	float NormalizeAngle( float fAngle )
    	{
    		if( fAngle < 0.0f )
    			fAngle += M_PI_F * 2.0f;
    
    		else if( fAngle > M_PI_F * 2.0f )
    			fAngle -= M_PI_F * 2.0f;
    
    		return fAngle;
    	}
    Last edited by Jadd; 11-25-2012 at 02:58 PM.

  4. #4
    mskc33's Avatar Member
    Reputation
    1
    Join Date
    Nov 2012
    Posts
    28
    Thanks G/R
    1/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @DarkLinux: I don't yet understand how CTM works. That'll come later
    @Jadd I already tried Atan2 but I think im doing something wrong. I tried to adapt the code you gave me to C#.

    Code:
    public void move() {
      Vector2 playerLocation = new Vector2(getPlayer().getLocation().X, getPlayer().getLocation().Y);
      Vector2 currentWaypoint = Waypoints[wpWalkIndex];
      float playerRotation = (float)(getPlayer().getRotation() * (180 / Math.PI)); // Not being used. What am I missing?
      float tRotation = getNormalizedAngle(getLinearAngle(playerLocation, currentWaypoint));
    }
    
    private float getLinearAngle(Vector2 from, Vector2 to) {
      Vector2 difVector = new Vector2(to.X - from.X, to.Y - from.Y);
      float fAngle = (float)Math.Atan2(difVector.Y, difVector.X);
      return fAngle;
    }
    
    private float getNormalizedAngle(float fAngle) {
      if (fAngle < 0f)
        fAngle += (float)Math.PI * 2.0f;
      else if (fAngle > (float)(Math.PI * 2.0f))
        fAngle -= (float)Math.PI * 2.0f;
      return fAngle;
    }
    I think what I'm missing is the current player rotation because I dont see how I have to calculate it with the whole thing.

  5. #5
    Master674's Avatar Elite User
    Reputation
    487
    Join Date
    May 2008
    Posts
    578
    Thanks G/R
    2/23
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by DarkLinux View Post
    I would use Click To Move,and let it do all the math for you... Or go and see how CTM sets the face direction.
    rofl...

    The math is so simple... just build the vector between the two points and get it's slope by Y/X, then do arcus tangens on it.
    The resulting value will be in -pi to +pi so you need to normalize that. Even a 3 year old can do this...

    Code:
    CVector2 vDiff = vDestination - vCurrent;
    float fPitch = vDiff.Y / vDiff.X; // It will rape your program if vDiff.X = 0
    float fAngle = atan( fPitch );
    return normalize0To2Pi( fAngle );
    Last edited by Master674; 11-25-2012 at 04:46 PM.

  6. #6
    Jadd's Avatar 🐸 Premium Seller
    Reputation
    1515
    Join Date
    May 2008
    Posts
    2,433
    Thanks G/R
    81/336
    Trade Feedback
    1 (100%)
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by mskc33 View Post
    @DarkLinux: I don't yet understand how CTM works. That'll come later
    @Jadd I already tried Atan2 but I think im doing something wrong. I tried to adapt the code you gave me to C#.

    I think what I'm missing is the current player rotation because I dont see how I have to calculate it with the whole thing.
    You only need two positions to calculate the angle between them. Your code works. What is the problem you are having now?

  7. #7
    mskc33's Avatar Member
    Reputation
    1
    Join Date
    Nov 2012
    Posts
    28
    Thanks G/R
    1/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem I'm having is: If I try to set the players rotation (unsecure, I know), the player looks in the wrong direction.
    Oh god its too late at night.... I think I'm missing something very obvious here.

    Code:
    public void move() {
      Vector2 playerLocation = new Vector2(getPlayer().getLocation().X, getPlayer().getLocation().Y);
      Vector2 currentWaypoint = Waypoints[wpWalkIndex];
      float playerRotation = (float)(getPlayer().getRotation() * (180 / Math.PI)); // Not being used. What am I missing?
      float tRotation = getNormalizedAngle(getLinearAngle(playerLocation, currentWaypoint));
    
      Magic.WriteFloat(getPlayer().BaseAddress + (uint)Pointers.WowObject.RotationOffset, (float)tRotation); // Doesnt work
      Magic.WriteFloat(getPlayer().BaseAddress + (uint)Pointers.WowObject.RotationOffset, (float)(getPlayer().getPlayerRotation() + tRotation)); // I tried both versions
    }
    
    private float getLinearAngle(Vector2 from, Vector2 to) {
      Vector2 difVector = new Vector2(to.X - from.X, to.Y - from.Y);
      float fAngle = (float)Math.Atan2(difVector.Y, difVector.X);
      return fAngle;
    }
    
    private float getNormalizedAngle(float fAngle) {
      if (fAngle < 0f)
        fAngle += (float)Math.PI * 2.0f;
      else if (fAngle > (float)(Math.PI * 2.0f))
        fAngle -= (float)Math.PI * 2.0f;
      return fAngle;
    }

  8. #8
    Jadd's Avatar 🐸 Premium Seller
    Reputation
    1515
    Join Date
    May 2008
    Posts
    2,433
    Thanks G/R
    81/336
    Trade Feedback
    1 (100%)
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    First of all, the GetLinearAngle function returns the exact rotation. You can simply call it and write the return value to the player's rotation, and it will work. There is no point where you need to get the player's current rotation - it is not used when calculating it.

    Second, all angle work is done in radians. I noticed you're stepping your "playerRotation" variable up to degrees. As I mentioned above, you do not need this variable at all, but even if you did, you should never use degrees in calculations. This is just a piece of advice for the future, if anything.

  9. #9
    mskc33's Avatar Member
    Reputation
    1
    Join Date
    Nov 2012
    Posts
    28
    Thanks G/R
    1/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It works! Thank you so much!! For anyone interested, here's how its working for me:

    Code:
    public void tick() {
      Vector2 playerLocation = new Vector2(getPlayer().getLocation().X, getPlayer().getLocation().Y);
      Vector2 currentWaypoint = Waypoints[wpWalkIndex];
    
      float tRotation = getNormalizedAngle(getLinearAngle(playerLocation, currentWaypoint));
      Magic.WriteFloat(LocalPlayer.BaseAddress + (uint)Pointers.WowObject.RotationOffset, getLinearAngle(playerLocation, currentWaypoint)); // It seems there is no need to normalize it?
    }
    
    private float getLinearAngle(Vector2 from, Vector2 to) {
      Vector2 difVector = new Vector2(to.X - from.X, to.Y - from.Y);
      float fAngle = (float)Math.Atan2(difVector.Y, difVector.X);
      return fAngle;
    }
    Once again Jadd, thank you! I wouldn't have made it without you (+Rep if I can)
    // Edit: Nope, can't give any rep -.- Sorry!

  10. #10
    Master674's Avatar Elite User
    Reputation
    487
    Join Date
    May 2008
    Posts
    578
    Thanks G/R
    2/23
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by mskc33 View Post
    It works! Thank you so much!! For anyone interested, here's how its working for me:

    Code:
    public void tick() {
      Vector2 playerLocation = new Vector2(getPlayer().getLocation().X, getPlayer().getLocation().Y);
      Vector2 currentWaypoint = Waypoints[wpWalkIndex];
    
      float tRotation = getNormalizedAngle(getLinearAngle(playerLocation, currentWaypoint));
      Magic.WriteFloat(LocalPlayer.BaseAddress + (uint)Pointers.WowObject.RotationOffset, getLinearAngle(playerLocation, currentWaypoint)); // It seems there is no need to normalize it?
    }
    
    private float getLinearAngle(Vector2 from, Vector2 to) {
      Vector2 difVector = new Vector2(to.X - from.X, to.Y - from.Y);
      float fAngle = (float)Math.Atan2(difVector.Y, difVector.X);
      return fAngle;
    }
    Once again Jadd, thank you! I wouldn't have made it without you (+Rep if I can)
    // Edit: Nope, can't give any rep -.- Sorry!
    You should really normalize it... Sure, normally it doesn't matter at all if you have like -90° or 270° but WoW always normalizes it between 0° and 360°

  11. #11
    Jadd's Avatar 🐸 Premium Seller
    Reputation
    1515
    Join Date
    May 2008
    Posts
    2,433
    Thanks G/R
    81/336
    Trade Feedback
    1 (100%)
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Master674 View Post
    You should really normalize it...
    Yep. If your rotation is < 0 or > +2pi you will disconnect on your next movement. Normalizing the angle is very much required.

  12. #12
    Master674's Avatar Elite User
    Reputation
    487
    Join Date
    May 2008
    Posts
    578
    Thanks G/R
    2/23
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Jadd View Post
    Yep. If your rotation is < -2pi or > +2pi you will disconnect on your next movement. Normalizing the angle is very much required.
    You mean < 0 and > 2pi

  13. #13
    Jadd's Avatar 🐸 Premium Seller
    Reputation
    1515
    Join Date
    May 2008
    Posts
    2,433
    Thanks G/R
    81/336
    Trade Feedback
    1 (100%)
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Master674 View Post
    You mean < 0 and > 2pi
    Yeah I do.

  14. #14
    mskc33's Avatar Member
    Reputation
    1
    Join Date
    Nov 2012
    Posts
    28
    Thanks G/R
    1/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay then, I will normalize it then.
    Look! Look what you've done!
    Thanks, once again.

  15. #15
    DarkLinux's Avatar Former Staff
    CoreCoins Purchaser Authenticator enabled
    Reputation
    1627
    Join Date
    May 2010
    Posts
    1,846
    Thanks G/R
    193/539
    Trade Feedback
    16 (100%)
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    @Master674
    As a 4th year engineering student, math is hard.

Similar Threads

  1. [Help] How to make a server Register?
    By LordAragon in forum World of Warcraft Emulator Servers
    Replies: 8
    Last Post: 11-11-2007, 02:19 PM
  2. [help] How to spawn
    By kanqaz in forum WoW ME Questions and Requests
    Replies: 1
    Last Post: 11-06-2007, 03:58 AM
  3. Help: How the **** do you play a Warrior =P?
    By The Mars Volta in forum World of Warcraft General
    Replies: 11
    Last Post: 09-11-2007, 03:54 PM
  4. Replies: 3
    Last Post: 08-17-2007, 08:32 AM
  5. Plz help: How to change character list layout?????/
    By srpskagarda in forum World of Warcraft General
    Replies: 3
    Last Post: 03-08-2007, 07:09 PM
All times are GMT -5. The time now is 10:05 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search