Need help with better/faster collision (overlap) detection

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • Hi, I'm making an RPG with controls where you have W and S to walk forward and backward, and A and D to turn your character (this makes it possible for the character to have more than 8 directions, as opposed to WASD for up left down right). To achieve this I'm using the bouncing ball movement for my player objects (I've got 2 player objects because I needed one for forward movement and an other one for backward movement, couldn't find an other way).
    The problem with the bouncing ball movement though is that unlike for custom movements, I don't know how to achieve pixel perfect collision detection.

    As you can see in the video, when my character walks into an obstacle (purple) it goes in too far. I would like the character to stop as soon as a collision detector (red) touches or overlaps an obstacle. Increasing the speed of the bouncing ball object makes it worse.

    Please login to see this media element.

    Furthermore you can also see how one of the collision detectors (blue) that it set to follow the player kind of lags behind the player. In this case it's not much of a problem but sometimes the red one lags behind too, making the character walk into obstacles even farther.

    Any solutions or other ways of doing this would be greatly appreciated.

    MFA: Please login to see this attachment.

  • Is there any specific reason why you're not using a custom movement?

    Well, either way (although it'd be easier with a custom movement) the thing you want to do is utilize fast loops to push your character out of objects.

  • Well, I didn't use a custom movement because for as far as I knew custom movements can only have a maximum of 8 directions (Up, down, left, right, and then diagonally). Do you know of a way to have the same kind of movement as in my MFA, but with a custom movement? (A&D for rotating the character, W&S for walking in the direction that the character is looking at)

  • Custom movements can be more versatile than that :)

    In this case you could use trigonometry.
    Rename two of the Character's alterable values to MyXpos and MyYpos and name another one to MySpeed and set it to 4.

    * While "W" is being pressed

    - Start loop "Move forward" MySpeed ("Character") times

    * On loop "Move forward"

    - Character: Set MyXpos to MyXpos ("Character") + 1.0 * Sin(Angle( "Character" ))
    - Character: Set MyYpos to MyYpos ("Character") + 1.0 * Cos(Angle( "Character" ))
    - Character: Set X position to MyXpos ("Character")
    - Character: Set Y position to MyYpos ("Character")

    Finally you need to add events to set the angle. I am sure you can handle that yourself :)

    Edited once, last by Popcorn (January 31, 2018 at 9:34 AM).

  • Thank you both very much! This fully custom movement is way better than the way I was doing it!
    However, I'm still having issues with moving into obstacles, and I don't know why.

    I've got it set up like this:

    * While "W" is being pressed
    * [X] (Front collision detector) is overlapping a backdrop
    (negated)
    - Start loop "Move forward" MySpeed ("Character") times

    * On loop "Move forward"
    * [X] (Front collision detector) is overlapping a backdrop
    (negated)
    - Character: Set MyXpos to MyXpos ("Character") + 1.0 * Sin(Angle( "Character" ))
    - Character: Set MyYpos to MyYpos ("Character") + 1.0 * Cos(Angle( "Character" ))
    - Character: Set X position to MyXpos ("Character")
    - Character: Set Y position to MyYpos ("Character")

    So normally as soon as the character walks 1 pixel into an obstacle, the loop should stop working, correct? However the character still seems to walk into obstacles for more than 1 pixel. Increasing the speed (the amount of loops) makes it walk into obstacles farther, even though this isn't supposed to happen since the remaining loops should stop starting as soon as the character is overlapping an obstacle.

    Updated MFA: Please login to see this attachment.

    Edited 2 times, last by Adnihil (January 31, 2018 at 6:02 PM).

  • You should reverse it and make it the obstacle overlaps a background, back your player object by removing a pixel from the value.

    Please login to see this link.
    Please login to see this link.|Please login to see this link.|Please login to see this link.

  • You should reverse it and make it the obstacle overlaps a background

    I'm sorry, I don't quite understand what you mean. Do you mean make it "[X] Obstacle is overlapping (Front collision detector)" instead? I tried that but it required me to make the obstacle an Active object instead of a backdrop (since backdrops can't be selected in the event editor), and the result was the same... I guess you meant something else?

    I don't understand why in the MFA I posted, the condition ''[X] (Front collision detector) is overlapping a backdrop'' gets ignored, making the loop play even though it shouldn't. Is this a bug?

    Edited 2 times, last by Adnihil (February 1, 2018 at 1:42 PM).

  • You need to add another event line in your fastloop. Something like:

    * On loop "Move forward"
    * (Front collision detector) is overlapping a backdrop
    - Character: Set MyXpos to MyXpos ("Character") - 1.0 * Sin(Angle( "Character" ))
    - Character: Set MyYpos to MyYpos ("Character") - 1.0 * Cos(Angle( "Character" ))
    - Character: Set X position to MyXpos ("Character")
    - Character: Set Y position to MyYpos ("Character")
    - Stop loop "Move forward"

    This needs to be after your forward movement event line. It will basically move you back one "step" and stop the loop from trying to move you any more.

    Quote

    I don't understand why in the MFA I posted, the condition ''[X] (Front collision detector) is overlapping a backdrop'' gets ignored, making the loop play even though it shouldn't. Is this a bug?

    This is because the check to see if you are overlapping is going to trigger on the NEXT event loop. So you will already be inside the backdrop when that is triggered. Hence the reason you need to add this extra code to reverse yourself out of the backdrop when it initially happens.

    Please login to see this link.


  • I tried doing this but it didn't seem to work...

    Quote


    This is because the check to see if you are overlapping is going to trigger on the NEXT event loop. So you will already be inside the backdrop when that is triggered. Hence the reason you need to add this extra code to reverse yourself out of the backdrop when it initially happens.

    But it doesn't trigger at all. If the speed (amount of loops) is set to 10, and the character is standing right next to an obstacle and you walk towards it, what's supposed to happen is it walks into the wall for 1 pixel (1 loop), and the remaining 9 loops nothing happens since it is now overlapping an obstacle, right? However what's happening is the character walks into the obstacle for the entire 10 loops (10 pixels), ignoring the condition, and only then stops (11th loop won't trigger).

    So to me this seemed like a bug OR I was wrongly understanding how fastloops work and actually the conditions are only checked for the first loop after which the remaining 9 loops will play regardless of the conditions. But then how do I reverse the character out of the obstacle before the screen is redrawn?

    Sorry, I know this is asking a lot, but could someone please take a look at the MFA I posted and fix it for me? I feel like I'm misunderstanding something that will seem really obvious once I see what I'm doing wrong.

  • Thank you very much for making that example, it's interesting to see how you did the movement. However the issue of walking into/over obstacles is still there. You can see this if you set the forward speed to 6 (instead of 3.0) and walk forward. Setting the speed to 60 will make the character enter the purple obstacle completely. Though in the actual game the speed would never be over 10, in theory the code shouldn't allow this to happen, should it? So it's a bug?

    Please login to see this media element.

  • Yes, thank you very much! :D
    After a lot of tinkering I found out that for some reason having a 'collision detector' Active object seperate from the 'Player' Active object made the movement of the player all weird and glitchy. Removing the collision detector Active(s) and using the Player Active as a collision detector itself fixed the issue.

    There's an other issue caused by the unstuck-loops though; when a part of the Player active is overlapping an obstacle (this can be achieved by standing next to an obstacle and rotating), moving forward will make the player move backwards, and moving backwards will make the player move forward. This allows the player to move through obstacles. Even with a round Player active this can still happen since it's impossible to make a perfect circle using square pixels.

    Please login to see this media element.

    I've been trying to find a fix for this for the past couple of hours, but to no avail (most of my issues come from rotating in corners). Do you happen to know any ways to prevent this from happening?

    I also just realised that something I was planning to do isn't going to work the way I thought it would. I wanted to make the player slide along obstacles when walking into them at an angle, instead of stopping completely and having to face 90° away from the obstacle to be able to move along it. I've tried searching for guides about this but don't really know what to look for. Does this type of movement have a name or something I could search for?

    Please login to see this attachment. (like this)

  • I would suggest to split the X and Y components of movement and use a separate detector for collisions anyway,
    you wont' have issues if the detector itself does not rotate

    see superquick example:
    Please login to see this attachment.

    (you can change player speed in "move_speed")

    the detector can be made invisible of course

    *** edit ***

    Added backward move and "rotating speed" value
    so it's more like what you need I guess?

    Please login to see this attachment.

    a selection of my Fusion examples can be found Please login to see this link.

    Edited once, last by schrodinger (February 6, 2018 at 9:39 AM).

  • I realize now that I made a mistake on the movement loop. It was not moving one step at a time, but pSpeed steps. I have fixed it now. I also separated the visual so the collision object now doesn't rotate, but the player visual does.

    As for your sliding along collision, it can be done but would require splitting the loops so that horizontal and vertical movement each have their own loop.

    Please login to see this attachment.

    Edit: Schrodinger, as always, did is a bit more elegantly than myself. He also separated the loops so you can slide. :P

    Please login to see this link.

    Edited once, last by mobichan (February 6, 2018 at 11:40 AM).

  • Alright! Thank you all so much! Looks like I was making things way more complicated than they should be!
    It's also interesting to see how things can be done in different ways. This was a good learning experience!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!