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

Get help using Construct 2

Post » Wed Feb 17, 2016 6:55 pm

Hi,

To be more precise, I have a cursor controlled by analog stick. Right now it can move in 8 directions, but I'd like to make it turning smoothly. What I'm after is moving the object at exact angle of the angle of right analog stick. Any clue how can I do that? Thanks
Last edited by megatronx on Thu Feb 18, 2016 1:13 am, edited 2 times in total.
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
78
S
21
G
19
Posts: 1,932
Reputation: 17,316

Post » Wed Feb 17, 2016 7:20 pm

Use the action:

Code: Select all
Move at angle
Move the object a number of pixels at a given angle in degrees
Mistakes were made.
B
47
S
23
G
107
Posts: 1,571
Reputation: 60,133

Post » Wed Feb 17, 2016 7:37 pm

oosyrag wrote:Use the action:

Code: Select all
Move at angle
Move the object a number of pixels at a given angle in degrees


Thanks, ut that's not what I'm after as this is what I'm doing right now, and only have 8 direction ( and I don't fancy manually creating more ). Instead I'm looking for a solution to get angle of the stick, so it moves always at exact angle f the stick, so you can rotate it with stick.
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
78
S
21
G
19
Posts: 1,932
Reputation: 17,316

Post » Wed Feb 17, 2016 10:05 pm

What is your stick? Is it a controller's analog stick (gamepad object), or did you create a touchscreen analog stick with sprites?

The formula for getting angle in degrees from coordinates is atan(changeinY/changeinX)

If you are making your own touch analog stick - compare stick's current position to the origin position to get change in Y and change in X, use the formula to get your angle from origin, and then use Move At Angle.
Mistakes were made.
B
47
S
23
G
107
Posts: 1,571
Reputation: 60,133

Post » Wed Feb 17, 2016 10:10 pm

oosyrag wrote:What is your stick? Is it a controller's analog stick (gamepad object), or did you create a touchscreen analog stick with sprites?

The formula for getting angle in degrees from coordinates is atan(changeinY/changeinX)

If you are making your own touch analog stick - compare stick's current position to the origin position to get change in Y and change in X, use the formula to get your angle from origin, and then use Move At Angle.


I use xbox gamepad. How would you do that with it?
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
78
S
21
G
19
Posts: 1,932
Reputation: 17,316

Post » Wed Feb 17, 2016 10:14 pm

Here is the manual entry for gamepad - https://www.scirra.com/manual/143/gamepad

I think what you are looking for is the following expression:

Axis(Gamepad, Index)
Retrieve the current position of an analog joystick on a specific gamepad. Index specifies left analog X and Y or right analog X and Y axes, subject to Key mapping. Axes range from -100 to 100. Axis values within the Analog deadzone are returned as 0.


So use this to get X and Y values that you can use in the arctangent formula.
Mistakes were made.
B
47
S
23
G
107
Posts: 1,571
Reputation: 60,133

Post » Wed Feb 17, 2016 10:16 pm

oosyrag wrote:Here is the manual entry for gamepad - https://www.scirra.com/manual/143/gamepad

I think what you are looking for is the following expression:

Axis(Gamepad, Index)
Retrieve the current position of an analog joystick on a specific gamepad. Index specifies left analog X and Y or right analog X and Y axes, subject to Key mapping. Axes range from -100 to 100. Axis values within the Analog deadzone are returned as 0.


So use this to get X and Y values that you can use in the arctangent formula.


Ok, will give it a try mate. Thanks
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
78
S
21
G
19
Posts: 1,932
Reputation: 17,316

Post » Thu Feb 18, 2016 12:19 am

Any clue what index right stick axes are?
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
78
S
21
G
19
Posts: 1,932
Reputation: 17,316

Post » Thu Feb 18, 2016 12:37 am

@Ashley, sorry, but could you help as this is really complicated to me. How can I get a cursor to follow 1:1 the right analog stick on 360 controler? What I'm after is moving the object at exact angle of the angle of right analog stick.
Last edited by megatronx on Thu Feb 18, 2016 1:07 am, edited 1 time in total.
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
78
S
21
G
19
Posts: 1,932
Reputation: 17,316

Post » Thu Feb 18, 2016 12:59 am

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.
B
10
S
1
G
1
Posts: 21
Reputation: 1,011

Next

Return to How do I....?

Who is online

Users browsing this forum: Emerson97, newt and 7 guests