Joystick MOBA movement

Ask gaming related questions (AHK v1.1 and older)
forus
Posts: 9
Joined: 07 Feb 2017, 19:48

Joystick MOBA movement

07 Feb 2017, 20:40

Help make movement work for all moba and dungeon crawler games in specific League of Legends because I'm to old to click a lot.

The goal is to use the joystick to move the character.

Others more clever than me created code to do so in Diablo 3, for reference:
#1 works great in d3, but am unable to transfer it to League of Legends
https://code.google.com/archive/p/diabl ... /downloads

#2 possibly useful code
https://autohotkey.com/board/topic/1033 ... d-control/
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Joystick MOBA movement

08 Feb 2017, 18:46

I have had a stab at stuff like this sometimes, I cannot stand point and click movement, hence the only mobas I play are generally WASD movement.

When you say Joystick movement - what do you mean? Do you want analog movement? I don't see how that would translate - clicking further away from your character surely does not move faster and invariably leads to more problems in my experience (ie you are more likely eg to click the other side of a wall and you start taking a crazy path).

If you just want to use joystick and don't care, then find a keyboard script that works, and I can help converting it to joystick input.
forus
Posts: 9
Joined: 07 Feb 2017, 19:48

Re: Joystick MOBA movement

08 Feb 2017, 19:51

Great minds think alike. :)

Exactly, the goal is the same as wasd movement except with 360 degress vs 8 directions.
But, either would be so much easier than clicking an ability on an enemy hero then clicking on the other side of the screen to run from them.
Good point, on the click distance being the same, just around the character to avoid strange pathing.
Not sure if useful, but these games allow the user to hold left click to move to that location.

What I've got, under wasd controls>wasd controls>program.cs. This uses in game position it extracts, instead of just center of the screen and mouse movement. So, not exactly what was asked...
https://github.com/TehBlaxxor/LeagueSharp

Similar code for Heroes of the Storm, only a picture of the code at the start, will reply if the creator messages me with the code.
https://www.youtube.com/watch?v=uGFRpRyUGA0
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Joystick MOBA movement

09 Feb 2017, 06:17

ahh right, yeah, I had not considered angle of movement as the analog bit.
That is a little more complex than 8 directions.

So yeah, we cannot really use a WASD move script as a basis.

I will think on this some more... Maybe knock something up this weekend.

Initially, I would probably knock up a stand-alone script, but I may have a bash at implementing this as a UCR plugin (See signature)
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Joystick MOBA movement

09 Feb 2017, 08:49

I had a little look in my lunch hour, and I think I understand what is needed.

Whilst we do not want stick position to govern *how far* from the character it clicks, we do want stick position to govern the *angle* from the character at which it clicks.

So looking at this page, it seems the process would be:

Convert stick position from cartesian coordinates (eg 100, 70) to polar coordinates (angle + distance).
Then modify the polar coords to keep the angle, but set the distance to a constant value.
Then convert the polar coords back to cartesian coords, which will give you the coordinates to click at.
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Joystick MOBA movement

09 Feb 2017, 11:40

So using the example numbers on the page I linked, I built the math functions that we will need:

Code: Select all

global pi := 3.141592653589793
a := CartesianToPolar(12,5)
b := PolarToCartesian(a.distance, a.angle)

CartesianToPolar(x, y){
	distance := Sqrt((x ** 2) + (y ** 2))
	angle := ATan(y / x)
	angle := RadToDeg(angle)
	return {distance: distance, angle: angle}
}

PolarToCartesian(distance, angle){
	angle := DegToRad(angle)
	return {x: distance * Cos(angle), y: distance * Sin(angle)}
}

RadToDeg(rad){
	return rad * (180 / pi)
}

DegToRad(deg){
	return deg * (pi / 180)
}
[Edit] This does not handle negative coords. Gonna ask Helgef for help ;)
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Joystick MOBA movement

09 Feb 2017, 12:49

Had some help from Helgef, here is a POC for converting input to output:

Code: Select all

InputCoords := {x: 0, y: 0}
OutputCoords := {x: 0, y: 0}

~Left::
	InputCoords.x := -50
	Gosub, UpdateCoords
	return
	
~Right::
	InputCoords.x := 50
	Gosub, UpdateCoords
	return

~Up::
	InputCoords.y := -50
	Gosub, UpdateCoords
	return

~Down::
	InputCoords.y := 50
	Gosub, UpdateCoords
	return

UpdateCoords:
	OutputCoords := GetCoords(InputCoords.x, InputCoords.y)
	Tooltip % OutputCoords.x ", " OutputCoords.y
	return

GetCoords(x, y){
	polar := CartesianToPolar(x, y)
	;polar.distance := 100
	cart := PolarToCartesian(polar.distance, polar.angle)
	return cart
}

CartesianToPolar(x, y){
	; returns angle in deg.
	distance := Sqrt((x ** 2) + (y ** 2))
	angle := getAngle(x,y)
	angle := RadToDeg(angle)
	return {distance: distance, angle: angle}
}

PolarToCartesian(distance, angle){
	; angle in rad
	angle := DegToRad(angle)
	return {x: distance * Cos(angle), y: distance * Sin(angle)}
}

RadToDeg(rad){
	return rad * (180 / pi)
}

DegToRad(deg){
	return deg * (pi / 180)
}

getAngle(x,y)
{
	; x,y, are coordinates in the plane.
	if (x=0)
		return 3*pi/2-(y>0)*pi
	phi:=atan(y/x)
	if (x<0 && y>0)
		return phi+pi
	if (x<0 && y<=0)
		return phi+pi
	if (x>0 && y<0)
		return phi+2*pi
	return phi
}

getQuadrant(phi)
{
	; phi angle, in rad
	if (phi>0 && phi <= pi/2)
		return 1
	else if(phi>pi/2 && phi <= pi)
		return 2
	else if( phi>pi && phi <= 3*pi/2)
		return 3
	else if (phi>3*pi/2 && phi <= 2*pi)
		return 4
	return -1
}
[Edit] It seems off for Down+Right - it gives 49.99992 for y instead of 50.
forus
Posts: 9
Joined: 07 Feb 2017, 19:48

Re: Joystick MOBA movement

09 Feb 2017, 17:50

EvilC, I appreciate you taking the time to make this dream a reality! hehe xd

Brainstorming why it's rounding is off in the 5th decimal place.
-Maybe pi is getting cut off early at around 5-8 decimal places, instead of 15? Not sure how many digits/decimal places global stores, or perhaps in a math operation it gets truncated. Because the math looks solid.

How can I test it? Also, don't mean to rush you, respond at leisure.
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Joystick MOBA movement

10 Feb 2017, 08:47

Well the slight rounding error is not a show-stopper in my book, so here is something testable for you.

It currently uses keys as input (As I do not have a stick handy), but the logic is entirely capable of dealing with analog input.

Run the script, make the game the active window then hit F12 to set window.
Use the arrow keys - the cursor should move around the character but the range of motion should be circular, not square (ie up left is not in the corner, but on a curve between left and up)

It currently DOES NOT CLICK, only moves the mouse.
We will need to put extra logic in to have it spam click repeatedly, as one click per input cycle will not be enough.

Code: Select all

#SingleInstance force

InputCoords := {x: 0, y: 0}
OutputCoords := {x: 0, y: 0}
CoordMode, Mouse, Window

F12::
	window := WinExist("A")
	WinGetPos, x, y, w, h, % "ahk_id " window
	cx := w / 2
	cy := h / 2
	return

~Left::
	InputCoords.x := -50
	Gosub, UpdateCoords
	return
	
~Right::
	InputCoords.x := 50
	Gosub, UpdateCoords
	return

~Left up::
~Right up::
	InputCoords.x := 0
	Gosub, UpdateCoords
	return

~Up::
	InputCoords.y := -50
	Gosub, UpdateCoords
	return

~Down::
	InputCoords.y := 50
	Gosub, UpdateCoords
	return

~Up up::
~Down up::
	InputCoords.y := 0
	Gosub, UpdateCoords
	return

UpdateCoords:
	OutputCoords := GetCoords(InputCoords.x, InputCoords.y, 100)	; 100 forces the output coord to always be 100px from center of screen, even if a diagonal
	;Tooltip % OutputCoords.x ", " OutputCoords.y
	MouseMove, % cx + InputCoords.x, % cy + InputCoords.y
	return

GetCoords(x, y, dist := 0){
	polar := CartesianToPolar(x, y)
	if (dist)
		polar.distance := dist
	cart := PolarToCartesian(polar.distance, polar.angle)
	return cart
}

CartesianToPolar(x, y){
	; returns angle in deg.
	distance := Sqrt((x ** 2) + (y ** 2))
	angle := getAngle(x,y)
	angle := RadToDeg(angle)
	return {distance: distance, angle: angle}
}

PolarToCartesian(distance, angle){
	; angle in rad
	angle := DegToRad(angle)
	return {x: distance * Cos(angle), y: distance * Sin(angle)}
}

RadToDeg(rad){
	return rad * (180 / pi)
}

DegToRad(deg){
	return deg * (pi / 180)
}

getAngle(x,y)
{
	; x,y, are coordinates in the plane.
	if (x=0)
		return 3*pi/2-(y>0)*pi
	phi:=atan(y/x)
	if (x<0 && y>0)
		return phi+pi
	if (x<0 && y<=0)
		return phi+pi
	if (x>0 && y<0)
		return phi+2*pi
	return phi
}

getQuadrant(phi)
{
	; phi angle, in rad
	if (phi>0 && phi <= pi/2)
		return 1
	else if(phi>pi/2 && phi <= pi)
		return 2
	else if( phi>pi && phi <= 3*pi/2)
		return 3
	else if (phi>3*pi/2 && phi <= 2*pi)
		return 4
	return -1
}
Converting this to stick will be easy - instead of passing in +50 or -50, we pass the joystick axis value.
Subtract 50 from the stick axis value, to give a range from -50...+50 instead of 0...100

Some form of deadzone enforcement will probably also be needed.
forus
Posts: 9
Joined: 07 Feb 2017, 19:48

Re: Joystick MOBA movement

10 Feb 2017, 15:05

Impressive fast progress. The circular arrow key position works in Diablo 3.

Things that could be improved:
1) It doesn't work in League of Legends for me. I set it up in Diablo 3, then I can minimize and make it work on the desktop, but no matter what I do, it doesn't cooperate in League of Legends. Perhaps a persistent profile could help...

2) The center of the circle is off a little off for my PC. The center of the circle is too low by may 50 pixels. When I click left arrow and click, I move left and down at around 20 degrees. Perhaps just my computer. Lenovo thinkpad 14" settings at 1920X1080. Tried fullscreen and windowed fullscreen same results.

If it isn't obvious, I'm excited about this. Also, message me your address and I'll send you a refurbished pc controller for testing thumbstick. That is, if in US or Canada because of how shipping works. If not, then I fail!
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Joystick MOBA movement

10 Feb 2017, 15:30

WinGetPos includes non-client area, you might need to call GetClientRect, or ClientGetRect (search msdn + dllcall) or whatever it is called, to get correct width and height for the center calculations. If you play fullscreen, use A_ScreenWidth/height.
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Joystick MOBA movement

10 Feb 2017, 15:32

Oh, I have tons of controllers, I just was at work earlier, but thanks for the offer.

When you say the center is off slightly, is the character not at the center of the screen.
Whatever, this will not be an issue long-term, it will be trivial to add an offset value.

Regarding LOL, what doesn't work? It doesn't move the mouse? I don't see how a game would stop a script interacting with the cursor.

Unless the cursor in LOL is not the windows cursor, but their own implementation?
forus
Posts: 9
Joined: 07 Feb 2017, 19:48

Re: Joystick MOBA movement

10 Feb 2017, 20:24

You're welcome.

Good call. It's got to be LOL used their own cursor, because it works in Heroes of the storm, just like D3. :)

Posted on League of Legends for how to access their cursor. Hopefully, they respond before 2025... Unless you, EvilC and Helgef have some magic code!
forus
Posts: 9
Joined: 07 Feb 2017, 19:48

Re: Joystick MOBA movement

12 Feb 2017, 21:00

No. But works fine in everything else.

Found that someone previously tried this and failed. Could be useful. But we will succeed! More like you will, and I'll be the hype man! hehe xd
https://autohotkey.com/board/topic/1070 ... se-cursor/

Asking in a few other LoL communities too. I'll get back as soon as possible, hopefully as soon as the E-sports spring split ends (it's on gaming TV right now). They wanna become like basketball. Maybe they can, but not with their funky mouse! Sorry ranting!

Edit: mousePos
They used mousePos to move the mouse to certain locations. Tried replacing mouse_Event with mousePos, but didn't work because I coded it wrong.
http://gamingonsteroids.com/topic/18525 ... entry89476

Will continue asking around because they may be using an overlay for the game.
forus
Posts: 9
Joined: 07 Feb 2017, 19:48

Re: Joystick MOBA movement

24 Mar 2017, 22:47

Hi EvilC and Helgef,

3 updates.

1. I have access to a program that would let us move the mouse in League of Legends. "GOS external"

2. Actually, been getting into Diablo 3 because I like the cooperative environment.

3. Trying to make a new key pad with a joystick. Got a partner learning SolidWorks, which should work to create a prototype.
New keypad required because the others only use a dpad or place the joystick in a position that causes hand cramps.

Will keep you updated on how that's going. As to have key controls and joystick worth of this project!
forus
Posts: 9
Joined: 07 Feb 2017, 19:48

Re: Joystick MOBA movement

22 Mar 2018, 12:07

Building a new keyboard.
Been saving up. Have enough funds for the parts and labor. Am a total noob at specific details.
Doesn't have to be perfect, just want a keyboard that works. Finally finished the model design on paper after years...
Wondering if you by chance know anyone who can build keyboards?
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Joystick MOBA movement

22 Mar 2018, 12:15

What are you after? A bunch of keys plus a joystick on the thumb or something?
Is that not essentially what a Logitech G13 is?

Regarding the DLLcall, I have no idea why I used this code:
F12::DllCall("mouse_event", "int", 0x8001, "uint", 32000, "uint", 1000)
It should be:
F12::DllCall("mouse_event", "int", 1, "uint", 100, "uint", 100)

I see no reason why LOL should not react to this - as what this does is fake mouse movement at a low level.
forus
Posts: 9
Joined: 07 Feb 2017, 19:48

Re: Joystick MOBA movement

22 Mar 2018, 12:28

EvilC!

I tested everything I could find on the market. They all make my hand cramp after about 10 minutes of games.

I'll message you the design so you can decide if it's worthy or not!

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 60 guests