Gamepad thumbstick aim within radius

Just started using Construct 2? Post your questions here

Post » Fri Mar 14, 2014 9:48 pm

I'd like to recreate functionality in the attached capx where instead of the mouse cursor, the gamepad right stick controls the player target in my top down game. The target needs to be set a fixed radius from the player (using pin behavior in bar mode).
Have looked through a number of gamepad examples but can't find the equivalent gamepad action for "Set Position to (Mouse.X, Mouse Y)"
You do not have the required permissions to view the files attached to this post.
B
5
S
1
Posts: 44
Reputation: 665

Post » Sat Mar 15, 2014 5:18 pm

you'll need to use the expression gamepad.axis(pad index, axis index)
it returns a number between -100 and 100 depending on how a pads stick is positioned.

'indexes' are zero based, which means gamepad 0 is the first, gamepad 1 is the second etc,
the axis indexes go like this:
left X = 0
left Y = 1
right X = 2
right Y =3

so gamepad.axis(0,2) will refer to the first gamepads right X axis
it will return -100 if the stick is fully to the left, 0 if in middle, 100 if fully right


I don't have a gamepad to test this with, but try this:

https://dl.dropboxusercontent.com/u/533 ... adAim.capx

if it works as intended the right analog stick should position the crosshair somewhere within a 200*200 square around the player
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Sat Mar 15, 2014 6:07 pm

That works but there are two issues. When the player moves (with the left stick) the target get left behind until the right stick is moved. I'd like the target to stay on the circumference of a circle which is at a 300 pixels radius from the Player's origin. This is why I was trying to use the Pin behavior in bar mode.

I'd also like the target to stay at the point on the circumference where it was left by the player on releasing the right stick. So that if only the left stick is being moved, the player can strafe/move in straight lines, rather than circle around the target which is what currently happens in your capx.

Not sure if this can be achieved without the Pin behavior.
B
5
S
1
Posts: 44
Reputation: 665

Post » Sat Mar 15, 2014 8:38 pm

of course it can

well, i hope this works.. like i said i don't have a gamepad to test it with

https://dl.dropboxusercontent.com/u/533 ... dAim2.capx

we can use the angle() expression, which returns the angle between two points like this: angle(x1,y1,x2,y2)

in this case we can just do angle(0,0,gamepad.axis(0,2),gamepad.axis(0,3))

this will basically return the current angle of the right stick, after that it's just a matter of positioning it a certain distance away from the player at this angle.

the disabled action in the .capx is an alternative way of doing this
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Sun Mar 16, 2014 10:51 am

That works, thanks.

One problem is that I want to restrict the 8direction movement to 4 directions. Works fine with the keyboard, but on the gamepad the left stick only allows up and down movement. Right and left movement are not detected when movement is restricted to 4 directions (via behavior properties). Have tried setting the default control flag to "No" and used different controllers so think it may be a Construct bug.
B
5
S
1
Posts: 44
Reputation: 665

Post » Tue Jun 06, 2017 9:05 pm

Hey @Keepee, I am searching for a way of doing this, get interested in your capx but he isn't there anymore, can you re-up or send to me pls?
B
22
S
11
G
4
Posts: 52
Reputation: 3,930


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 4 guests