How do I move the object exactly at angle of analog stick?

Get help using Construct 2

Post » Thu Feb 18, 2016 1:05 am

Olgoth wrote:Hi Megatronx, Is something like this what you are looking for?

Code: Select all
https://www.dropbox.com/s/qf88r9zb2bfwn24/mouse_sustitution.capx?dl=0


Basically you create a second "mouse", if the real mouse is still visible I guess you could make "at the start of layout" > mouse > Set cursor style > none.

That way the mouse would be invisible when it overlaps the game window.
I hope it helps.


No. I have that already. What I'm after is moving the object at exact angle of the angle of right analog stick. So if I press the stick at 78 degrees, that will be the angle the object moves.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Thu Feb 18, 2016 1:14 am

megatronx wrote:Any clue what index right stick axes are?


I haven't used this object myself yet, but you could test this pretty quickly. I've made a capx for you. I hope it works, I can't check myself as I don't have a gamepad hooked up.

https://www.dropbox.com/s/8pes8gkyav87f ... .capx?dl=0

The reason it probably isn't specified is because there are many different gamepads out there, each with different amounts of input axes/mappings.
Mistakes were made.
B
52
S
26
G
108
Posts: 1,606
Reputation: 61,133

Post » Thu Feb 18, 2016 1:22 am

oosyrag wrote:
megatronx wrote:Any clue what index right stick axes are?


I haven't used this object myself yet, but you could test this pretty quickly. I've made a capx for you. I hope it works, I can't check myself as I don't have a gamepad hooked up.

https://www.dropbox.com/s/8pes8gkyav87f ... .capx?dl=0

The reason it probably isn't specified is because there are many different gamepads out there, each with different amounts of input axes/mappings.


Thx, but don't have installed latest beta.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Thu Feb 18, 2016 3:35 am

Probably to get the angle of the right stick it would be:
angle(0,0,gampad.axis(0,2),gamepad.axis(0,3))
B
92
S
32
G
109
Posts: 5,290
Reputation: 70,991

Post » Thu Feb 18, 2016 8:34 am

Get the input for both the horizontal and vertical axes of the stick you want.

angle = arcTan( stickY/stickX )

moveVector( cos(angle), sin(angle) )

Do whatever to make the code work. Using the arctangent from the stick data will get you the true angle, and using cosine and sine as the X/Y movement increments will ensure it moves in the correct direction. Increment at whatever units you're using.

Hopefully that helps.
B
2
Posts: 1
Reputation: 152

Post » Thu Feb 18, 2016 1:00 pm

R0J0hound wrote:Probably to get the angle of the right stick it would be:
angle(0,0,gampad.axis(0,2),gamepad.axis(0,3))


YES!!! Thanks!!! Brilliant!!!
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Tue Sep 12, 2017 8:36 am

Hello and sorry that i reanimated this older thread ;)
But is there a different in the quality and precision between different gamepads?
For example, is a XBox-controller more accurate and precise then a cheaper version (like Gamesir G3w or CSL GamepadX or Logitech-Stuff, etc.)?

Because, when i use the code above, the angle will not exactly been shown - only in some kind of 45 degree-steps (sometimes i got really precise angle-values, then it stucks in 45 degree but i still move the analog-stick, then it jumps to 72 degrees and shows the exact angle till i'm on 90 degree, then it stuck again, etc.).

Also when i only show the axes: when i slowly move the analog-stick to the right side, a value only starts to shows when i reach a quarter of the path i can move the stick. Also the value starts at around 30, then it calculate exactly till i reach 100 - but there i'm not at the end of the way i could move the stick. There's only been shows values between the first and the penultimate section i can move the stick.

Sorry for my english and i hope you understand what i mean :)
B
22
S
6
G
2
Posts: 185
Reputation: 3,632

Previous

Return to How do I....?

Who is online

Users browsing this forum: BackendFreak, kalibark2, Mohicano and 29 guests