User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 16

Thread: Need help with better/faster collision (overlap) detection

  1. #1
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Adnihil's Avatar
    Join Date
    Oct 2016
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help with better/faster collision (overlap) detection

    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.



    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: Attachment 24534

  2. #2
    Clicker Fusion 2.5

    Join Date
    Oct 2007
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Adnihil's Avatar
    Join Date
    Oct 2016
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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)

  4. #4
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Popcorn's Avatar
    Join Date
    Jun 2006
    Location
    Norway, Bergen
    Posts
    2,345
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)
    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

  5. #5
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Adnihil's Avatar
    Join Date
    Oct 2016
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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: top down rpg new movement.mfa

  6. #6
    Clicker Fusion 2.5Fusion 2.5 Mac
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    zip2kx's Avatar
    Join Date
    Jun 2015
    Posts
    781
    Mentioned
    17 Post(s)
    Tagged
    0 Thread(s)
    You should reverse it and make it the obstacle overlaps a background, back your player object by removing a pixel from the value.

  7. #7
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Adnihil's Avatar
    Join Date
    Oct 2016
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by zip2kx View Post
    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?

  8. #8
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export ModuleUnicode Add-on
    mobichan's Avatar
    Join Date
    Oct 2007
    Location
    Buffalo, NY
    Posts
    3,281
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    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.

    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.

  9. #9
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Adnihil's Avatar
    Join Date
    Oct 2016
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mobichan View Post
    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.
    I tried doing this but it didn't seem to work...

    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.

  10. #10
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export ModuleUnicode Add-on
    mobichan's Avatar
    Join Date
    Oct 2007
    Location
    Buffalo, NY
    Posts
    3,281
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    Here is a super simple sin/cos movement. You can change the speed and rotation angle to suit your needs. Hope this helps you understand what is going on.
    Attached files Attached files

Page 1 of 2 1 2 LastLast

Similar Threads

  1. Way to replace obj overlap with collision
    By Huntermanx in forum Fusion 2.5
    Replies: 6
    Last Post: 31st July 2017, 12:06 PM
  2. Problem: Overlap detection is checking by the highest x and Y of an object
    By Stranger in forum Multimedia Fusion 2 - Technical Support
    Replies: 0
    Last Post: 30th July 2015, 12:12 AM
  3. Polygon or pixel collision . which is faster?
    By Yima in forum Fusion 2.5
    Replies: 4
    Last Post: 14th January 2014, 10:31 AM
  4. overlap (custom collision detection) issue
    By Hamcraft in forum Multimedia Fusion 2 - Technical Support
    Replies: 6
    Last Post: 26th May 2011, 02:08 PM
  5. Background collision vs. overlap question
    By Drcooper in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 9th August 2010, 10:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •