8-Direction Sliding

0 favourites
  • 4 posts
From the Asset Store
Character Sprite Pack: Walk 4 Directions made in illustrator
  • I don't remember when the "Allows Sliding" property was added to the 8-direction behavior, but I thought it was exactly what I was looking for in my project. The player could get snagged on some solids in spots and I thought it could help gracefully slide around objects at times.

    It did help, but I noticed it caused a lot of shaking at times. When I held on the movement controls to keep the player moving into a solid either several objects would shake or the entire screen would shake, maybe due to scrollTo behavior on the player is shaking the viewport/camera.

    I'm not wanting to file a bug report (or complain) as I seem to have found one solution: Turn on pixel rounding in the project. I'm not wanting to do this in my project as it seems to make the camera movement choppy at times.

    Another solution to the shaking objects it to make sure objects are at integer pixel values themselves. I tested that and it stopped objects from shaking. This didn't stop the entire screen from shaking at times though, as I assume that is caused by the player being at a non-pixel value.

    Instead of trying to troubleshoot this and add a bunch of changes (in my large project) to prevent this, I thought it might be better to re-create this functionality. I always view pre-built functionality, such as behaviors, as quicker to use but less flexibility, whereas custom solutions can take longer (sometimes much longer) to create but can be fully customized.

    In this case I mainly just want players to not get stuck going through doorways as easy. At least that was the only real spot I was getting caught on. I don't have that many diagonal (non-rectangle) solids in my project so I don't need much sliding. So I don't even need to re-create the entire functionality; I just need something very specific.

    Trying to think how the sliding functionality works under the hood, I figured if moving down and running into a solid, it might simply check if the object can continue to move down if moved slightly to the left or right. I thought that might be why the screen shakes - as the sliding mechanic keeps moving the objects back and forth to check for slidability.

    I created a sprite that if overlapping with the player while moving the event would set the player's X value over one pixel. A bit to my surprise, it worked and looked as smooth as can be! I added some variables to the object to control direction and amount and came up with this event:

    Now I'm not sure this will be my final solution. I just came up with it and I'm not excited about having to have four extra sprites in the project for each doorway. But it definitely is helping so I'm gonna roll with it for now, fine tune it as I go, but also be open to trying completely new solutions.

    GIF: imgur.com/a/v0bCft1

    So why am I posting this? One is just to share this in case anyone else is looking into this. But though I don't have a specific question I'm asking, I would love any additional info on any of the topics I've brought up or corrections on some of the assumptions I've made. So for example:

    • Anyone else experience the shaking when allow sliding enabled? Any other solutions to resolve?
    • How does allow sliding work under the hood? (I actually haven't looked if any of Construct's code/repos are public)
    • Has anyone implemented their own custom sliding mechanic?
  • This example based on angle the object overlap with:

    dropbox.com/scl/fi/zn7y83woxpntzk6k311fn/Avoid_Obstacles_PUSH.capx

  • Here’s some older examples of custom solutions for wall sliding.

    construct.net/en/forum/construct-2/how-do-i-18/8-direction-behavior-slide-95148

    Wall sliding usually works by finding the closest direction an object can move and stop overlapping. Also the velocity is canceled along that direction.

    No idea how construct is doing that under the hood currently, but in c2 it would do the push out by checking positions around the object’s starting position till a free space was found.

    In the examples above it would treat the player as a circle and find the closest distance from the player to the edges of the box to find the closest direction. But there are other ways.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for those suggestions. After playing around with this a bit more I think what I setup works for now. If I need to update this later I'll keep what you two posted in mind.

    I felt like making a minute long dev vlog video about this:

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