Collision not working
Posted: Mon Jan 20, 2020 12:16 pm
I don't know why, but colliders works only in one place(upper middle)
Code: Select all
for k, object in ipairs(Objects.list) do
if object.name ~= "p_right_leg" and object.name ~= "p_left_leg" and object.name ~= "p_head" and object.name ~= "p_body"
and object.name ~= "p_right_arm" and object.name ~= "p_left_arm" then
if object.solid then
print(object.name .. ": " .. "x: " .. object.x .. ", y: " .. object.y .. "; width: " .. object.width .. ", height: " .. object.height .. ";")
LeftCollision = checkCollision(LeftCollider.x, LeftCollider.y, LeftCollider.width, LeftCollider.height, object.x, object.y, object.width, object.height)
RightCollision = checkCollision(RightCollider.x, RightCollider.y, RightCollider.width, RightCollider.height, object.x, object.y, object.width, object.height)
UpCollision = checkCollision(UpCollider.x, UpCollider.y, UpCollider.width, UpCollider.height, object.x, object.y, object.width, object.height)
DownCollision = checkCollision(DownCollider.x, DownCollider.y, DownCollider.width, DownCollider.height, object.x, object.y, object.width, object.height)
end
object.x = object.x - Movement.x
object.y = object.y - Movement.y
end
end
Code: Select all
-- First, initialize all to false.
LeftCollision = false
RightCollision = false
UpCollision = false
DownCollision = false
for k, object in ipairs(Objects.list) do
if object.name ~= "p_right_leg" and object.name ~= "p_left_leg" and object.name ~= "p_head" and object.name ~= "p_body"
and object.name ~= "p_right_arm" and object.name ~= "p_left_arm" then
if object.solid then
print(object.name .. ": " .. "x: " .. object.x .. ", y: " .. object.y .. "; width: " .. object.width .. ", height: " .. object.height .. ";")
-- Now, we do: variable = variable or checkCollision... for each of the variables
LeftCollision = LeftCollision or checkCollision(LeftCollider.x, LeftCollider.y, LeftCollider.width, LeftCollider.height, object.x, object.y, object.width, object.height)
RightCollision = RightCollision or checkCollision(RightCollider.x, RightCollider.y, RightCollider.width, RightCollider.height, object.x, object.y, object.width, object.height)
UpCollision = UpCollision or checkCollision(UpCollider.x, UpCollider.y, UpCollider.width, UpCollider.height, object.x, object.y, object.width, object.height)
DownCollision = DownCollision or checkCollision(DownCollider.x, DownCollider.y, DownCollider.width, DownCollider.height, object.x, object.y, object.width, object.height)
end
object.x = object.x - Movement.x
object.y = object.y - Movement.y
end
end