[Resolved] How do I smooth the collision?

0 favourites
  • 3 posts
  • Hello,

    Sorry if this question has already been answered, I've looked around without finding anything helpful. But I'm not sure I'm using the correct vocabulary..

    I'm using the awesome MoveTo behavior made by rexrainbow to control my character from a top point of view.

    I'm clicking/touching the screen to make my character move in a direction (using the Touchwrap plugin)

    However, if there is an obstacle, the character will very abruptly stop. Even if it's just at a corner or if the angle of movement is very small.

    Is there a clean and efficient way to smooth the collisions and make my character move or slide against the obstacle when moving at an angle?

    I've tried 2 things, unsuccessfully:

    -First I thought I had to know what was the position of the obstacle compared to the character. I've created some kind of sprite on each sides to detect overlap and know what where was the wall.

    Then knowing that I use the direction angle to move the position of the characters on X or Y.

    However. It works if I'm checking only one dimension but if there is 2 at the same time, it doesn't really behave smoothly and even jump sometimes(if the characters is in a corner for example)

    The think the solution will tend toward this idea but I was wondering if anyone have a clear example of how to achieve that idea.

    -The other idea is a bit clunky. If there is contact with obstacle, I use a pathfinding behavior to go around. It works but it's a bit slow and not really what I had in mind..

    If anyone as a suggestion, please let me know!

    Thank you.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • No worries for asking questions. It’s often hard to find answers to old questions.

    Sounds like you’re onto the start of a working solution.

    Basically all that’s needed to wall slide is to move out of the wall in the closest direction when you overlap a wall. The two parts to this is detecting where the walls are and moving away from the walls.

    Detectors can work for the first, but you have to be careful with the collision boxes.

    The moving out can be done by just moving out by a bit from each overlapping wall, using the detectors to know which direction.

    Here’s a rough example.

    Repeat 10 times

    — position detector sprites

    — detectorLeft is overlapping wall

    —— sprite: move right 1 pixel

    — detectorRight is overlapping wall

    —— sprite: move left 1 pixel

    ...and so on for up and down.

    So something like that would move out a max of 10 pixels out of the walls, a pixel at a time. Could prove jittery though, so you can make it move by less than 1 pixel. Also if it doesn’t move far enough you’d increase the repeats. It’s a balance between jittery and fast or smoother yet slow.

    There is also the custom movement behavior’s push out action. It does stuff like the above with one action. Could be useful.

    There are jumping issues with that behavior so here is a more precise solution. Makes very smooth wall sliding. Hopefully simple enough to copy paste over.

    construct.net/en/forum/construct-2/how-do-i-18/how-do-i-make-the-8-direction-95148

  • Interesting! Thank you so much for taking the time to reply.

    Indeed moving the sprite pixel by pixel until it's not overlapping is kind of hard to fine tune and avoid jittering.. But it's better than what I had.

    The link you also provide is also perfectly work, it's impressive and perfect for what I'm doing!

    Thanks again for sharing it!

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