diff --git a/examples/scenes/gameplay/moveplayer/actors/player.lua b/examples/scenes/gameplay/moveplayer/actors/player.lua index b0436b4..2a8a47d 100644 --- a/examples/scenes/gameplay/moveplayer/actors/player.lua +++ b/examples/scenes/gameplay/moveplayer/actors/player.lua @@ -2,6 +2,7 @@ local Player = actor { type = "player", dimensions = {w = 16, h = 16}, + friction = {x = 480*3, y = 480*3}, isSolid = true, visuals = { mode = "box", @@ -14,8 +15,6 @@ function Player:onInit() end function Player:update(dt) - self.friction.x, self.friction.y = 480*3, 480*3 - if love.keyboard.isDown("up") then self.speed.y = -120 end diff --git a/framework/scenes/world/actors/physics/init.lua b/framework/scenes/world/actors/physics/init.lua index 17e501f..1a48860 100644 --- a/framework/scenes/world/actors/physics/init.lua +++ b/framework/scenes/world/actors/physics/init.lua @@ -33,12 +33,12 @@ local physicsUtils = require "framework.scenes.world.actors.physics.utils" function Physics:initPhysics(position, dimensions, isSolid) self.position = Vector3D(position.x, position.y, position.z or 0) self.speed = Vector3D(0, 0, 0) - self.friction = Vector3D(0, 0, 0) - self.gravity = Vector3D(0, 0, 0) - self.gravityAxis = "" - self.bounceFactor = 0 - self.isSolid = (isSolid == true) + self:setGravity(self.def.gravity or {}) + self:setFriction(self.def.friction or {}) + self.bounceFactor = self.def.bounceFactor or 0 + + self.isSolid = (self.def.isSolid == true) self.haveCollisions = true @@ -74,7 +74,8 @@ end -- Setter functions -function Physics:setGravity(axis, value) +function Physics:setGravity(gravity) + local axis, value = gravity.axis or "", gravity.value or 0 self.gravity = Vector3D(0, 0, 0) self.gravityAxis = axis or "" if (self.gravityAxis == "") then @@ -91,6 +92,10 @@ function Physics:setGravity(axis, value) end end +function Physics:setFriction(friction) + self.friction = Vector3D(friction.x or 0, friction.y or 0, friction.z or 0) +end + -- Getter functions -- Help to get informations from the physics