Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Web Development
You last visited: Today at 18:14

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Face target (QUESTION, 2D, Angle, Rotation)

Discussion on Face target (QUESTION, 2D, Angle, Rotation) within the Web Development forum part of the Coders Den category.

Reply
 
Old   #1
 
DarkElite99's Avatar
 
elite*gold: 0
Join Date: Apr 2014
Posts: 375
Received Thanks: 34
Face target (QUESTION, 2D, Angle, Rotation)

Hello

I am coding a small bot/script for a TOP-DOWN 2D browser game, in JAVASCRIPT...
Actually I got prety nice work done, like:
- Movement (but without angle...)
- Auto teleport /party / heal, etc...
- Restart bot/script when server restart
- Read command from ADMIN(me) through chat
But... I am really bad with maths (i guess this thing about angle is all about maths)...

Hopefuly can get yours help

So here goes the question:
How to get correct ANGLE, so I (P1) face Target (P2(), knowing only:
*- P1 X and Y
*- P2 X and Y

My objective:
Is to make player follow target, facing it.
It work moving backwards, forwards and sidewards, but I want to make player follow the target, moving forward (so it needs to be facing it)

A simple draw...

P1 is currently facing 0º
I want P1 to face something like 20º
DarkElite99 is offline  
Old 01/04/2020, 21:37   #2
 
DarkElite99's Avatar
 
elite*gold: 0
Join Date: Apr 2014
Posts: 375
Received Thanks: 34
Code:
function getAngleDeg(ax,ay,px,py) {
    var angel = {
        x: ax,
        y: ay
    };
    var player = {
        x: px,
        y: py
    };
    var x = player.x - angel.x;
    var y = player.y - angel.y;
    var radianAngle = Math.atan2(x, y);
    var northUpAngle = radianAngle * 180/ Math.PI;
    if (x < 0 && y < 0) {
        northUpAngle += 360;
    }
    return northUpAngle.toFixed(0)
}
got it! Thanks anyway
#plsClose=true
DarkElite99 is offline  
Old 01/04/2020, 21:38   #3


 
False's Avatar
 
elite*gold: 0
The Black Market: 243/0/0
Join Date: Apr 2011
Posts: 11,118
Received Thanks: 2,435
Arrow General Coding -> Web Development

#moved
False is offline  
Reply

Tags
2d, javascript, js, rotation, top-down


Similar Threads Similar Threads
[Guide] How to find the angle of your character to your desired target
04/07/2024 - Cabal Guides & Templates - 2 Replies
Hello guys, For those who are eager to put Autoit into action for use with CABAL, you would be glad with this post. Lots of people PMed me on how did I manage to rotate my character so that it faces the right direction when botting. I do that using trigonometry! (oh no) But don't run away - yet Complicated as it seems, it is just this function in AutoIt that does the magic.
WTB 2KK on Thor , Face to Face
02/22/2010 - Aion Trading - 10 Replies
hi , da ich bisschen schiss hab kinah vom großhändler zu kaufen, versuch ich es ma hier ;D wie geschrieben , will 2kk auf thor , face to face halt ... zahle 22€ über paypal ASMODIER.



All times are GMT +2. The time now is 18:14.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.