Gamepad thumbstick aim within radius

0 favourites
  • 6 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • 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'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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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

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

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

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