How do I fix this collision bug?

Not favoritedFavorited Favorited 0 favourites
  • 3 posts
From the Asset Store
Particles support animations, collisions, effects and etc.
  • Okay, so I'm trying to make a platformer without ANY behaviors, just pure events, and I've got the horizontal movement going, but now theres another problem, gravity.

    The actual falling is working completely fine, but the ground collision isn't, the player keeps sinking into the ground, can anyone help me fix this?

  • How can we help you without your code?

    Please attach the *.c3p file; this will make it easier for us to resolve the issue.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If you're just doing it in events without behaviors, you will also need to handle the collisions with events too. That involves checking for an overlap with obstacles and then moving out of the obstacle and maybe updating the velocity.

    There are many ways to do that, but one way to do an event based movement for a jump with gravity would be:

    on any key pressed
    -- sprite: set vy to -100
    
    every tick:
    -- sprite: add 100*dt to vy
    -- sprite: set y to self.y+vy*dt
    
    sprite: y > 400
    -- sprite: set y to 400
    -- sprite: set vy to 0

    That last event acts as the collision detection and response for a ground at y=400. Likely you'd want to collide with actual objects but that would get more involved.

    One possible solution could be to move backwards till no longer overlapping. or in the case of landing on some ground you'd move it up.

    on any key pressed
    -- sprite: set vy to -100
    
    every tick:
    -- sprite: add 100*dt to vy
    -- sprite: set y to self.y+vy*dt
    
    sprite: vy>0
    while
    sprite: overlaps ground
    -- sprite: set y to self.y-1
    -- sprite: set vy to 0

    You'd likely want something similar when moving up, left, and right, just need to go backwards by pixel steps (or smaller steps to have smaller gaps). A common technique is to handle horizontal movement first, then vertical movement.

    Instead of moving backwards in steps it is possible to calculate exactly how far to move the object to not be overlapping, but that's less trivial to do.

    You could also utilize a behavior that has control turned off as a quick way to handle the collision response for you, but you get less control, and usually they work better when it's that behavior that moves the object.

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