Phyzzle Physics
Posted: Fri Oct 07, 2016 6:09 pm
removed
Code: Select all
function Map:move(e, dx, dy)
if not self:collision(e, dx, 0) then e:move(dx, 0) end
if not self:collision(e, 0, dy) then e:move(0, dy) end
end
Code: Select all
--- x Acceleration
xa = 0,
--- y Acceleration
ya = 0,
It does in a subtle way: typically you want to separate the two colliding shapesgamedevaton wrote:I chose to check separate axis ... it doesn't affect the collision handling negatively in any way.
I haven't studied the code a lot, but with inheritance through metatables -gamedevaton wrote:For my implementation there is a benefit to using meta tables for entities, inheritance and overriding functionality. See Player.lua and Elevator.lua which override the update and collision response functions. A meta table implementation also gives you the benefit of having each Entity point to a shared "copy" of a function rather than that same function being redefined on each Entity table.
Velocity is always added to position and acceleration to velocity.I use those variables in Player.lua in the example to accumulate gravity (acceleration) and therefore it is velocity. I have updated the comment thank you. It is also completely optional to use those variables in your Entity implementation. The only essential things an entity needs is location and dimension variables, an update function, collision response and movement response functions.
Code: Select all
-- gravity acceleration
self.yv = self.yv + self.gravity <-- needs *dt here too
dy = dy + self.yv