[Math] Finding a distance 20 yards between 2 positions menu

User Tag List

Results 1 to 8 of 8
  1. #1
    Tanaris4's Avatar Contributor Authenticator enabled
    Reputation
    148
    Join Date
    Oct 2008
    Posts
    646
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Math] Finding a distance 20 yards between 2 positions

    So please delete if you feel this isn't appropriate, but I'm sure many bots may use something similar (which are using CTM).

    Basically if I have 2 positions (player position, destination), I'd like to have the player walk towards the destination, but only walk within 20 yards of the destination.

    I could obviously just tell CTM to walk towards the destination and have a timer that checks how close I am, but I'd like to be exact if possible.

    I have done some work in the past, but frankly it didn't work 100% of the time, am I missing something simple here?

    Code:
    - (Position*)positionAtDistance:(float)distance withDestination:(Position*)playerPosition {
    
            // this is where we want to face!
            float direction = [playerPosition angleTo:self];
            float x, y;
    
            // negative x
            if ( [self xPosition] < 0.0f ){
                    x = -1.0f * (cosf(direction) * distance);
            }
            // positive x
            else{
                    x = -1.0f * (cosf(direction) * distance);
            }
            
            // negative y
            if ( [self yPosition] < 0.0f ){
                    y = -1.0f * (sinf(direction) * distance);
            }
            // positive y
            else{
                    y = -1.0f * (sinf(direction) * distance);
            }
            
            Position *newPos = [[Position alloc] initWithX:([self xPosition] + x) Y:([self yPosition] + y) Z:[self zPosition]];
            return [[newPos retain] autorelease];
    }
    Thanks in advance!
    https://tanaris4.com

    [Math] Finding a distance 20 yards between 2 positions
  2. #2
    MaiN's Avatar Elite User
    Reputation
    335
    Join Date
    Sep 2006
    Posts
    1,047
    Thanks G/R
    0/10
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    Vector3 start = ...;
    Vector3 end = ...;
    Vector3 dir = end - start;
    dir.Normalize();
    Vector3 positionThatIs20YardsAwayFromEnd = end - dir * 20;
    [16:15:41] Cypher: caus the CPU is a dick
    [16:16:07] kynox: CPU is mad
    [16:16:15] Cypher: CPU is all like
    [16:16:16] Cypher: whatever, i do what i want

  3. #3
    Tanaris4's Avatar Contributor Authenticator enabled
    Reputation
    148
    Join Date
    Oct 2008
    Posts
    646
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you provide the Vector3 class? I'm on a mac + will have to re-create in Objective-C

    Edit: I'm guessing this doesn't exist now that I found Vector3 true?
    Last edited by Tanaris4; 06-13-2011 at 04:02 PM.
    https://tanaris4.com

  4. #4
    MaiN's Avatar Elite User
    Reputation
    335
    Join Date
    Sep 2006
    Posts
    1,047
    Thanks G/R
    0/10
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Tanaris4 View Post
    Can you provide the Vector3 class? I'm on a mac + will have to re-create in Objective-C

    Edit: I'm guessing this doesn't exist now that I found Vector3 true?
    It's any basic vector3 class. Here's one with the required methods:

    Code:
    public struct Vector3
    {
         public float X, Y, Z;
    
         public void Normalize()
         {
             float magnitude = (float)Math.Sqrt(X * X + Y * Y + Z * Z);
             X /= magnitude;
             Y /= magnitude;
             Z /= magnitude;
         }
    
         public static operator Vector3 -(Vector3 left, Vector3 right)
         {
         left.X -= right.X;
             left.Y -= right.Y;
             left.Z -= right.Z;
             return left;
         }
    
       public static operator Vector3 *(Vector3 left, float right)
       {
           left.X *= right;
           left.Y *= right;
           left.Z *= right;
           return left;
       }
    }
    [16:15:41] Cypher: caus the CPU is a dick
    [16:16:07] kynox: CPU is mad
    [16:16:15] Cypher: CPU is all like
    [16:16:16] Cypher: whatever, i do what i want

  5. #5
    suicidity's Avatar Contributor
    Reputation
    207
    Join Date
    Oct 2006
    Posts
    1,439
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Asking for a Vector class is like asking for dirt, you can find it everywhere and depending on where you go it will change very slightly.. But it's there if you want your handful/pocketful of it.


  6. #6
    EmilyStrange's Avatar Active Member
    Reputation
    34
    Join Date
    Jul 2009
    Posts
    125
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Vector (math) classes in Objective-C can be found all over the web with a quick Google search.

    You can also just tell CTM to set a range of 20 yds. Give CTM the target location or unit GUID and a distance of X yds. Works every time. I use it on my hunters that need to stay back by 25-30 yds.

    Unless you are specifically wanting to always be at 20 yds, in which case you would want to be able to back off, which can be dangerous on bridges. For that you want to turn 180 degrees and just run back to a position that is X yds away from the target, assuming you are using CTM. If you are using keys/movement flags, you can figure the distance you would need to move, and work out whether it would be faster to turn and run and turn again, or just walk backwards.

  7. #7
    suicidity's Avatar Contributor
    Reputation
    207
    Join Date
    Oct 2006
    Posts
    1,439
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    He may want to do it manually for more control, as you could easily interpolate enemy positions for average range from target ( assuming they're moving ). Added bonuses is he could eliminate updating/relying on parts of CTM, including using a different movement method completely.

    If he's falling back on CTM though, the CTM implementation would work just fine.


  8. #8
    gononono64's Avatar Contributor
    Reputation
    100
    Join Date
    Jul 2009
    Posts
    85
    Thanks G/R
    1/5
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay so, you can simply use

    Code:
    Distance = (DestinationY-PlayerY)^2 + (DestinationX-PlayerX)^2
    Distance = Sqrt(Distance)
    *note not real code*

    If you want him to run within 20 yards just do distance - 20

    I hope that what you meant anyways or that i helped in someway... or if thats even correct xD ... anyways i'm going back to my boonie shack cya
    Hi! My name is Devon and I’m an alcoholic. Moving on…
    https://www.ownedcore.com/forums/world-of-warcraft/world-of-warcraft-bots-programs/wow-memory-editing/319172-guide-how-make-wow-bot-complete-newbs.html

Similar Threads

  1. how to check Distance between pet and target ? GetAreaMapInfo got error
    By wowmacro in forum WoW Bots Questions & Requests
    Replies: 3
    Last Post: 11-10-2014, 06:56 PM
  2. [LUA] - Distance between player and unit.
    By Synnoid in forum WoW UI, Macros and Talent Specs
    Replies: 1
    Last Post: 09-08-2012, 09:01 AM
  3. [Exploit] Find out if an opposite faction player is online
    By Matt in forum World of Warcraft Exploits
    Replies: 7
    Last Post: 11-04-2006, 09:22 AM
  4. wats the difference between an exploit and a hack? :S
    By thomas005 in forum Community Chat
    Replies: 2
    Last Post: 06-18-2006, 09:08 AM
All times are GMT -5. The time now is 07:01 AM. 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