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

0 Favourites
• 17 posts
• 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

• Use the action:

``````Move at angle
Move the object a number of pixels at a given angle in degrees[/code:j92xkjfx]``````
• Use the action:

``````Move at angle
Move the object a number of pixels at a given angle in degrees[/code:28sy298i]
``````

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.

• 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.

• 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?

• 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:

[quote:1d48ezpy]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.

• 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:

[quote:1iqz9ynz]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

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• Any clue what index right stick axes are?

• 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.

• Hi Megatronx, Is something like this what you are looking for?

``````https://www.dropbox.com/s/qf88r9zb2bfwn24/mouse_sustitution.capx?dl=0[/code:2mlr4vg8]

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.``````
• Hi Megatronx, Is something like this what you are looking for?

``````https://www.dropbox.com/s/qf88r9zb2bfwn24/mouse_sustitution.capx?dl=0[/code:257551y6]

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.

• 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.

• > 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.

• Probably to get the angle of the right stick it would be:

angle(0,0,gampad.axis(0,2),gamepad.axis(0,3))

• 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)