How to move sprite with touch based stick and collisions?

0 favourites
  • 7 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'm trying my hand at a simple touch-based mobile dungeon crawler. I got to a point where any option seems to lack something so basic and yet I'm so close to nailing it. Maybe someone can give me an idea.

    I tried more than one way top solve this so skip the next two paragraphs if you want to get straight to the point.

    So first I thought grid-based movement would be easier to manage, but was I wrong. It's pretty easy to move the player with the keyboard, but using touch to select one of 4 directions is so clunky.

    So I started using behavior MoveTo - to Touch Position XY. That works as intended mostly. The player moves towards the coordinates where I'm touching the screen, and stops at solids. I wasn't happy though that the player would completely stop when reaching a solid instead of kind of sliding around it. Looking for a solution for that, I came across a touch stick tutorial, straightforward enough, so I added that too. (in case anyone's interested, this what I used construct.net/en/tutorials/touch-stick-controllers-241/page-4 ).

    Ok, now my problem is, I can move the player by detecting the angle the stick is pulled to, but it won't stop on solids.

    I suspect this is because I'm moving the player by "Size/Position>Move at angle" instead of actually "MoveTo>Move to position", which seems to comply with collisions. However, how can use MoveTo to go to a certain direction then and not toward a position?

    Here's my project. 1drv.ms/u/s!AlBF-Ft-T2VNsIYWv9-Bx4zTJGY8Ug

    Here's my event sheet.

    Thanks for any help.

    Tagged:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I would suggest something like Line Of Sight in conjunction with Pathfinding.

    Bool variable "canmove" =1

    - player has Los to touchx,touchy, move to touchx,touchy.

    -else set "canmove" to 0,player find path to touchx,touchy.

    Player on path finished, set "canmove" to 1

    It can only be as smart as you make it.

  • I would suggest something like Line Of Sight in conjunction with Pathfinding.

    Bool variable "canmove" =1

    >- player has Los to touchx,touchy, move to touchx,touchy.

    >-else set "canmove" to 0,player find path to touchx,touchy.

    Player on path finished, set "canmove" to 1

    It can only be as smart as you make it.

    Thanks for the reply. That could be one way to make it with TouchXY, but it kinda kills the idea of moving with the stick.

    Do you know if there's a way to use MoveTo in an angle maybe?

  • Player coordinates are relative.

    Also Los has raycasting.

  • Player coordinates are relative.

    Hmmm are you saying I could convert angle to a position in the same angle? That could work! I don't know how to do it but it seems like a proper workaround.

    Also Los has raycasting.

    What is raycasting?

    By the way, before moving further into line of sight, I'd be worried about the fact that your suggestion included pathfinding, something I found to be very erratic in real time/every tick.

  • Line of sight allows you to cast a ray at an angle to check for collisions.

    Cast the ray in the direction you are moving via whatever control.

    Also you absolutely should not use pathfinding every tick.

    Its should be asynchronous every time. That's what the Boolean variable is for.

  • I think I got it. Instead of moving at an angle, I added behavior 8-direction. I was using ranges of angles to change the animations (for example if stick was pulled from 45º to 135º the player was changed to sprite looking down). Those same ranges can Simulate 8 Direction. For diagonals, all I needed to do was to widen the ranges some 30º each.

    Now it acts exactly as I intended, the control stick works and the player won't be completely blocked by solids, it slowly slides around them when moving diagonally. I feel like I leveled up!

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