How do I set up Twin-Stick Controls?

0 favourites
  • 14 posts
From the Asset Store
This is a twin stick shooter similar to Enter the gungeon,Nuclear Throne, Helldivers & Soul knight for the mobile device
  • Hello! I've been watching Jeremy Alexanders video on YouTube about setting up a Twin-Stick control scheme, I have the movement down okay, but I am having issue with moving the Recital with the Right Stick. I have it set up where a bullet fires from the tip of a sword, mouse movement works fine. Here is the Event Sheet logic.

    + System: Every tick

    -> Camera: Set position to (lerp(Self.X, Player.X,0.10), lerp(Self.Y, Player.Y,0.10))

    -> Reticle: Set position to (Mouse.X, Mouse.Y)

    -> Sword: Set position to (Player.ImagePointX("Sword"), Player.ImagePointY("Sword"))

    -> Sword: Set angle toward (Reticle.X, Reticle.Y)

    + Gamepad: Gamepad 0 Right analog X axis ≠ 0

    -> Reticle: Set Bullet angle of motion to angle(0,0,Gamepad.Axis(0,2),Gamepad.Axis(0,3)) degrees

    -> Reticle: Set Bullet speed to Gamepad_Speed

    + System: Else

    -> Reticle: Set Bullet speed to 0

  • I'm guessing the problem is with setting Reticle to mouse position on every tick. You should do it only when mouse is moving.

    Also, "reticle" is the aim/target mark, right? Why are you moving it with bullet behavior? Try "Move at angle" action instead:

    Reticle position to (player.x, player.y)

    Reticle move distance(0,0,Gamepad.Axis(0,2),Gamepad.Axis(0,3))*10 pixels at angle(0,0,Gamepad.Axis(0,2),Gamepad.Axis(0,3))

  • Indeed the Right Stick is for aiming the Recital. And I have the Retical for both the Mouse and Right stick, I dont know if that Mouse.x, Mouse.Y interferes with the Right Stick. But I put in the logic you suggested Dop2000, I'll post it below. But as of right now when I move the right stick, the Retical moves from the screen on to the Player sprite and then back to where it was originally.

    + Gamepad: Gamepad 0 Right analog X axis ≠ 0

    -> Reticle: Move distance(0,0,Gamepad.Axis(0,2),Gamepad.Axis(0,3))×10 pixels at angle angle(0,0,Gamepad.Axis(0,2),Gamepad.Axis(0,3))

    -> Reticle: Set position to (Player.X, Player.Y)

  • No, the order of actions is wrong. First, set to player position, then move at angle.

  • Check out this demo I made, it allows to aim with mouse or gamepad:

    dropbox.com/s/tt8sqfxmnkcxikf/GamepadMouseAim.capx

  • Okay I flipped the Logic like you suggested, but the Right Stick still does not move. I also tried downloading that game you sent to my Dropbox but it will not open.

  • What do you mean - you can't download it, or you can't open the file in Construct 3? What is the error message?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It says .capx files can’t be previewed. I tried to download it into my Dropbox, but every time I try to open it, it freaks out my Chrome browser, constantly tries to open new windows.

  • Don't try to preview it in Dropbox! Simply download the file (to your hard drive, not to your dropbox) and then open it in Construct 3 editor.

  • I downloaded it properly and was able to see your game and check out the logic you used. Though after applying it to my game, the right stick does not move like your demo. In fact the sword I am using to swing around the player, Rectical should follow, moves almost in only 4 directions and always comes to a stop pointing lower-right. The Rectical does not follow and after going from mouse to stick and back again to mouse, the mouse no longer functions properly. I added all the Global events like your demo and placed the Logic at the very top of my Event List. Here is what I have so far.

    + System: Mouse.X ≠ Mouse.X

    + OR System: Mouse.Y ≠ Mouse.Y

    -> System: Set mouseX to Mouse.X

    -> System: Set mouseY to Mouse.Y

    -> System: Set control to "mouse"

    + System: Else

    ----+ Gamepad: Gamepad 0 Right analog X axis ≠ 0

    -----> System: Set control to "gamepad"

    + System: control = "mouse"

    -> Reticle: Set position to (Mouse.X, Mouse.Y)

    + System: Else

    + System: control = "gamepad"

    -> Reticle: Set position to (lerp(Self.X, ((Gamepad.Axis(0,2)+100÷200))×LayoutWidth, dt×10), lerp(Self.Y, ((Gamepad.Axis(0,3)+100)÷200)×LayoutHeight, dt×10))

    + System: Every tick

    -> Camera: Set position to (lerp(Self.X, Player.X,0.10), lerp(Self.Y, Player.Y,0.10))

    -> Sword: Set position to (Player.ImagePointX("Sword"), Player.ImagePointY("Sword"))

    -> Sword: Set angle toward (Reticle.X, Reticle.Y)

    + System: On start of layout

    -> Camera: Set Invisible

    -> Mouse: Set cursor to None

    + Reticle: Is overlapping Sprite

    -> Reticle: Set animation frame to 1

    + System: Else

    -> Reticle: Set animation frame to 0

  • It's very hard to read the code written like this, and I don't know how your project is set up. It will be much easier if you could post your project file.

  • Great News, I got things working properly. The right stick and mouse both move the Retical. Though I noticed if I change the game layout size, the logic stops working and the right stick does not work again. Is there a way to modify something to where I can make my game maps bigger without breaking the logic? I tried to modify some of this logic... but without success.

    -> Retical: Set position to (lerp(Self.X, ((Gamepad.Axis(0,2)+100)÷200)×LayoutWidth, dt×5), lerp(Self.Y, ((Gamepad.Axis(0,3)+100)÷200)×LayoutHeight, dt×5))

  • If your layout is bigger than the screen, use OriginalWindowWidth, OriginalWindowHeight instead of layoutWidth and layoutHeight.

  • Okay, Got it. Thanks! :)

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