Discord
Login
Community
DARK THEME

Quick Engine: Theres an issue with colliding on a left wall

It's something strange that happens when, for example, the player moves to the left wall. It doesn't clip, but, looks like, i don't know how to describe it, is like when you jump below a platform. The player is bopping his head over and falling to the ground, but because the keyboard.UP and player.grounded clause, the player is constantly jumping and falling. This happens also when the platform is a short distance between the player. OK, Ctrl+C and Ctrl+V what i said, but this time the player.grounded clause doesn't appear.

This is all the code RELEVANT for solving this issue, and can be help-full for other projects. HOWEVER, this is just a test code, and not the final project.
MAIN

init = function()
  Quick.init()
  player_init()
  map = Quick.addMap("map", 0, 0, 240, 160)
end

update = function()
  Quick.update()
  player_update()
end

draw = function()
  Quick.draw()
end

PLAYER

player_init = function()
  player = Quick.addSprite("icon", 0, 0, 10, 10)
end

player_update = function()
  if keyboard.LEFT then player.vx = -100
  elsif keyboard.RIGHT then player.vx = 100
  else player.vx = 0
  end
  
  if keyboard.UP and player.grounded then
    player.vy = 100
  end
end

This is using vanilla Quick Engine ver. 1.1

This is the effect of how the physics engine works and how it detects collisions and what it does in the event of a collision.

  • in each update loop it is detected whether the player has pressed a direction key.
  • when this happens the player object is given a velocity (player.vx field)
  • the physics engine is called, (Quick.update()).
  • the engine calculates the new position of the player based on the vx, ax, vy, ay fields and gravity.
  • the player is moved and a collision is tested
  • if a collision of the player with a wall or the ground is detected, the engine changes the direction of the forces so that they are opposite to the player's. This should cause the player to be pushed off the wall or ground.
  • This works for a single collision. But it may happen that there will be multiple collisions. Then glitches appear. For example, if you stack several dozen boxes on top of each other, they can start to bounce on their own.
  • In more advanced physics engines, smaller simulation steps are used, and several iterations of the entire world per frame. Such effects become less visible.

I recommend calling it first

  player_update()  
  Quick.update()

It won't remove the glitch - but it may reduce the effect.

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community