Gamepad analog sticks for rotation

Get help using Construct 2

Post » Sun Feb 01, 2015 11:04 pm

Hi everyone,
I was working on the controls for my game and thought it might be cool to aim at the angle the thumb sticks are pointing, much like a twin-stick shooter.
Right now the controls are set up to only aim at 45 degree angles, but thought finer controls when aiming might be nice. Unfortunately it gets a lot more complicated.

Does anyone have any ideas on how to set this up? I would really appreciate any advice.

Thanks! :D
Be sure to check out my Metroidvania game, A Hole in the Earth
B
59
S
24
G
3
Posts: 359
Reputation: 5,683

Post » Sun Feb 01, 2015 11:20 pm

All you really need for this is to get the angle at which your analog stick is pointing, which you can get using the following expression:

Code: Select all
angle(0, 0, Gamepad.Axis(GamepadIndex, XAxisIndex), Gamepad.Axis(GamepadIndex, YAxisIndex))

You would, of course, replace GamepadIndex, XAxisIndex, and YAxisIndex with the desired indices for the gamepad and analog stick you're wanting to check on. After getting this angle, it should be pretty straightforward to point/shoot/whatever an object in that direction.
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,116

Post » Mon Feb 02, 2015 5:08 am

Thanks for the reply @linkman2004!
I hate to say this, for fear that I'm probably going to sound really dumb, but how do I write the expression to find the correct thumbstick and axis? I assumed the gamepad index was 0 since it's player one.
How about I write what I had as I might not even be close. :P

Every tick ---- Gun - Set angle to atan(Gamepad.Axis(0, Index?) / Gamepad.Axis(0, Index?))

The manual just says, "Index specifies left analog X and Y or right analog X and Y axes, subject to Key mapping. Axes range from -100 to 100.", which is quite vague.
Be sure to check out my Metroidvania game, A Hole in the Earth
B
59
S
24
G
3
Posts: 359
Reputation: 5,683

Post » Mon Feb 02, 2015 6:43 pm

The expression to get the angle is going to look exactly as I wrote it, but with the indices replaced -- no need to use atan. I can't give exact indices(depends on the controller), but if I had to hazard a guess I would say:

GamepadIndex = 0
XAxisIndex(Left stick) = 0
YAxisIndex(Left stick) = 1
XAxisIndex(Right stick) = 2
YAxisIndex(Right stick) = 3
...

The only way to find out for sure is to run tests. Set the angle of an object to the expression I gave with various indices and see what works.
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,116

Post » Tue Feb 03, 2015 2:28 am

Thanks @linkman2004! I will try that out right away. :)
Be sure to check out my Metroidvania game, A Hole in the Earth
B
59
S
24
G
3
Posts: 359
Reputation: 5,683

Post » Tue Feb 03, 2015 3:13 am

Yep, @linkman2004, your indices were correct for the axis and thumbstick.
Thanks so much for the help!
Be sure to check out my Metroidvania game, A Hole in the Earth
B
59
S
24
G
3
Posts: 359
Reputation: 5,683

Post » Mon Feb 09, 2015 11:13 pm

I was just about to post a similar question, thanks to linkman2004 for answering and ryanrbot for beating me to the punch!
B
14
S
6
G
1
Posts: 1
Reputation: 1,681


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, GrogIsGood, plinkie, rayolf and 6 guests