Page 1 of 6 1 2 3 ... LastLast
Results 1 to 10 of 51

Thread: Issue with horizontal collision with moving platform

  1. #1

    Issue with horizontal collision with moving platform

    Greetings! Sorry for all the threadspam, but my problems are many!

    I have horizontally moving platforms, but the whole platform is also an obstacle that you should collide with as if it were a backdrop.
    Movement is fastloop based, the platform is moved forward 1 pixel every loop, and the loop is done 2 times.
    In the loop, after the platform is moved, i check for collision with the player. If there is collision, i move the player the same amount of pixels in the same direction.
    So it goes

    Move platform
    check collision, move player
    move platform,
    check collision, move player

    but somehow, the player gets stuck in the platform, one or two pixels. Like the collision doesn't happen until the loop has finished, and only runs on the second run.

    Any ideas?

  2. #2
    Sounds like the infamous "overlap issue",
    you can search the forum for this,
    this very issue has plagued many projects and given many sleepless nights around here

    In short, when you test for overlap between A and B
    only "A" position will be "updated" at current frame
    "B" position will be tested as if it was one frame behind
    thus you can't have direct real time pixel-perfect collision testing between two active objects

    unless you use some pretty impractical workaround
    some currently known are:

    - "foreseeing" the position A will have next frame, and then test overlap with B as if it was checked one frame later, so it should give you the result of current frame...
    - test your collisions only using math (very handy and performant if you have "square" collision masks)
    - destroying and re-creating your B object upon collision test, this will force a coordinate refresh

    Casleziro and KingCool struggled a lot on this and may have additional hints

  3. #3
    Aaah thank you for telling me this, I thought I was going crazy. I thought the collision happened in a fastloop there would be no such problems, but I guess not. Thank you!

  4. #4
    So I did some thinking and thought about the following way to check mathematically for collision
    To cover all cases of collisions, I think I need 4 events

    xLeft("Player") > X("Platform")
    xLeft("Player") < (X("Platform")+Width("Platform")
    yTop("Player") > (Y("Platform")
    yTop("Player") < (Y("Platform")+Height("Platform")

    xLeft("Player") > X("Platform")
    xLeft("Player") < (X("Platform")+Width("Platform")
    yBot("Player") > (Y("Platform")
    yBot("Player") < (Y("Platform")+Height("Platform")

    xRight("Player") > X("Platform")
    xRight("Player") < (X("Platform")+Width("Platform")
    yTop("Player") > (Y("Platform")
    yTop("Player") < (Y("Platform")+Height("Platform")

    xRight("Player") > X("Platform")
    xRight("Player") < (X("Platform")+Width("Platform")
    yBot("Player") > (Y("Platform")
    yBot("Player") < (Y("Platform")+Height("Platform")

    And if either is true, X("Player") = X("Player")+xVelocity("horizontalPlatform")

  5. #5
    Well, it works better now but still not perfect.

    Currently I got the events

    X Position of Group.Movable = Range(X( "Group.Movable" ), ( X Left( "Player" ) - OWidth( "Group.Movable" ) ) + 1, X Right( "Player" ) - 1)
    Y Position of Group.Movable = Range(Y( "Group.Movable" ), ( Y Top( "Player" ) - OHeight( "Group.Movable" ) ) + 1, Y Bottom( "Player" ) - 1)

    To check for collision. This works great, Group.Movable being the qualifier for horizontal platformers in my case.

    If the above conditions are true, players X Position is set to X( "Player" ) + ( ( horiz( "Group.Movable" ) / Abs(horiz( "Group.Movable" )) ) )
    This means the players position will be changed by either -1 or +1, depending on if the horiz of the platform is negative or positive.

    Now this works well, except for two things. If I walk against the platform from the right, and the platform is moving to the left, I "bounce" away from it sort of, not a smooth collision.
    And sometimes the player still gets stuck in it, I'm guessing if he's colliding with it from the right while the value is negative, he'll be moved one pixel into the platform due to how it is set up.

    But setting it up like this seems to be the only way to make it work dynamically no matter which side of the platform you are colliding with it from. Is there something I'm missing here?

  6. #6
    Here's a quick example, see if it can be of any help:


    I've put in a viewport object to magnify the collision zone,
    if you don't have and don't want to install this (extremely cool ) extension
    let me know and I'll provide an example without it

  7. #7
    Hello schrodinger! I tried your example and that does indeed work, but I'm having a hard time implementing it into my own engine, due to the platforms movement not being in a fastloop and several other things occuring outside fastloops.
    Is there a way to make it fully fastloop-integrated for better control?

  8. #8
    Clicker Fusion 2.5
    casleziro's Avatar
    Join Date
    Mar 2013
    United States
    Storsorgen, sorry for the delay but with my current schedule I have little to no time to be on the forums lately (which is why I almost never reply to private messages and am rarely seen recently).

    Schrodinger's example (using math) is definitely the most performant and least headache-inducing method to work with concerning "solid" moving platforms. They're a tedious gimmick to implement in Fusion regardless, as is anything that requires fine collision thanks to the legendary overlap bug, which triggers this face whenever I have to deal with it
    michael phelps.jpg

    You don't need to worry about the platform movement not being in a fastloop in order to implement it into your engine: Lines 12 and 13 in Schrodinger's example is where everything important happens (assuming we're just going off of X axis. You would need to do something similar for Y as well if your platform had Y movement). Now:

    1) Firstly, make note of where Schrodinger placed the hotspots of the player and the platform; this is crucial to the method he used to check for boundaries.
    2) Line 12 should occur in your player's own movement loop. This is the collision for your player against the platform
    3) Line 13 should be below both your player movement and your platform movement, and does not require a loop. This line merely checks if the platform would have overlapped the player's boundaries, and moves the player the same distance the platform had just moved if so. You would replace + Round(Cos(timer / 10)) to whatever your platform moved in your engine (usually the difference between the platform's position before it has moved and its position after the move. You can get this difference if your engine doesn't supply it via values normally by storing the platform's position in a value before the loops that move your platform happen (in an always event), then make another always event after your loops that sets that same value to current position("platform")- value
    Last edited by casleziro; 12th August 2016 at 06:17 AM.

  9. #9
    Casleziro, the placement of the hotspot is important in his code, but couldn't I simply replace the X references to X Left("Player")?

    Edit: Ah can only do a check of X, not X Left.

  10. #10
    Ok, so I tried implementing this in my engine but it's still not working. At speeds of 1 pixel moved per frame it works, but not if the player moves more. I've attached an example to illustrate!


    The only thing I changed was how the player is moved, and how many steps. Hotspot should be in the right spot and everything.

Page 1 of 6 1 2 3 ... LastLast

Similar Threads

  1. Replies: 4
    Last Post: 2nd June 2015, 12:21 PM
  2. Horizontal Moving Platform using Platform Movement Object example
    By Warmachine in forum Guides, Tutorials, Examples, Widgets
    Replies: 0
    Last Post: 20th January 2015, 10:31 PM
  3. 2 Platform Movements overlapping on a moving platform
    By SuperDisk in forum Multimedia Fusion 2 - Technical Support
    Replies: 6
    Last Post: 2nd July 2013, 12:20 AM
  4. Moving Platform in Platform Movement Object
    By radel999 in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 16th July 2012, 02:49 PM
  5. Horizontal moving platform
    By K1kk0z90 in forum Multimedia Fusion 2 - Technical Support
    Replies: 0
    Last Post: 23rd January 2011, 06: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