Mouvement and Looking
Added the ability to move left and right Added the ability to sprint / run Added Gravity Added Jumping (Might remove later)
This commit is contained in:
parent
dd2757c261
commit
1c2fb970bb
2 changed files with 129 additions and 0 deletions
43
physics.lua
43
physics.lua
|
|
@ -0,0 +1,43 @@
|
|||
function gravity(object, dt)
|
||||
if object.bools.isAirborne == true then
|
||||
object.physics.airtime = object.physics.airtime + dt
|
||||
end
|
||||
if clearanceCheck(object, dt) == "ground" then
|
||||
object.y = ground.y - (object.height + 1)
|
||||
object.physics.velocityY = 0
|
||||
object.physics.airtime = 0
|
||||
object.bools.isAirborne = false
|
||||
elseif object.y ~= ground.y - (object.height + 1) then
|
||||
object.bools.isAirborne = true
|
||||
end
|
||||
object.physics.gravity = 4.91*object.physics.airtime
|
||||
if object.physics.velocityY + object.physics.gravity > object.physics.terminalVelocity then
|
||||
object.physics.velocityY = object.physics.terminalVelocity
|
||||
else
|
||||
object.physics.velocityY = object.physics.velocityY + object.physics.gravity
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function mouvement(object, dt)
|
||||
object.y = object.y + object.physics.velocityY
|
||||
object.x = object.x + object.physics.velocityX
|
||||
if object.bools.isWalking == false and object.physics.velocityX ~=0 then
|
||||
object.physics.velocityX = 0
|
||||
end
|
||||
if not object.bools.isRunning and math.abs(object.physics.velocityX) > object.attributes.maxRunningSpeed + 0.1 then
|
||||
if object.physics.velocityX > 0 then
|
||||
object.physics.velocityX = object.attributes.maxRunningSpeed
|
||||
else
|
||||
object.physics.velocityX = object.attributes.maxRunningSpeed * -1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function clearanceCheck(object, dt)
|
||||
if ground.y <= object.y + object.height + object.physics.velocityY + 1 then
|
||||
return "ground"
|
||||
else
|
||||
return "GTG"
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue