The character passes through the slab along the x coordinate
Posted: Sat Sep 28, 2024 4:15 pm
Basically the player moves through the platform at the x coordinate since I don't do anything with it. How to make sure that when the CheckCollision function detects an intersection of objects, the player returns back
I did this through Google Translate so I think it won’t be very clear what I meant
main.lua
conf.lua
And this library
I did this through Google Translate so I think it won’t be very clear what I meant
main.lua
Code: Select all
function love.load(arg)
if arg and arg[#arg] == "-debug" then require("mobdebug").start() end
camera = require "libraries/camera"
cam = camera()
platforma = {}
player = {}
wall={}
player.x = 300
player.y = 400
player.width = 60
player.height = 120
player.hp = 100
player.speed = 300
player.gravity = 600
player.jump = 200
platforma.x = 0
platforma.y = 900
platforma.width = 1800
platforma.height = 30
wall.x = 200
wall.y = 850
wall.width = 50
wall.height = 50
end
function love.update(dt)
if CheckCollision(player, platforma) then
--I don't know what's here
else
player.y = player.y + player.gravity*dt
end
if love.keyboard.isDown("a") then
player.x = player.x - player.speed*dt
elseif love.keyboard.isDown("d") then
player.x = player.x + player.speed*dt
elseif love.keyboard.isDown("w") then
--хз че писать
end
cam:lookAt(player.x, player.y)
end
function love.draw()
cam:attach()
love.graphics.setBackgroundColor(0,0,0)
love.graphics.setColor(1,1,0,1)
love.graphics.rectangle("fill", player.x, player.y, player.width, player.height)
love.graphics.setColor(0,0.4,0,1)
love.graphics.rectangle("fill", platforma.x, platforma.y, platforma.width, platforma.height)
love.graphics.setColor(0.5,0,0,1)
love.graphics.rectangle("fill", wall.x, wall.y, wall.width, wall.height)
cam:detach()
end
function CheckCollision(object1, object2)
local x1 = object1["x"]
local x2 = object2["x"]
local y1 = object1["y"]
local y2 = object2["y"]
local width1 = object1["width"]
local width2 = object2["width"]
local height1 = object1["height"]
local height2 = object2["height"]
return x1 < x2+width2 and
x2 < x1+width1 and
y1 < y2+height2 and
y2 < y1+height1
end
Code: Select all
function love.conf(t)
t.window.width = 1900
t.window.height = 1000
t.window.vsync = 0
t.window.title = "Test"
t.window.borderless = false
t.window.resizable = false
end