bump.lua incorrect output/input

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Sosolol261
Party member
Posts: 125
Joined: Wed Nov 26, 2014 6:43 am

bump.lua incorrect output/input

Post by Sosolol261 »

Hello guys!

Let's get to the code first.

Code: Select all

-- in movingTestThing.lua

mtt = {}

function mtt:load()
	self.x = 100
	self.y = 100
	self.w = 32
	self.h = 32
	self.speed = 500
	self.loaded = true
	world:add(mtt, self.x, self.y, self.w, self.y)
end

function mtt:move(dt)
	if love.keyboard.isDown("w") then
		local actualX, actualY, cols, len = world:move(mtt, self.x, self.y - self.speed * dt)
		self.x = actualX
		self.y = actualY
	end
	if love.keyboard.isDown("a") then
		local actualX, actualY, cols, len = world:move(mtt, self.x - self.speed * dt, self.y)
		self.x = actualX
		self.y = actualY
	end
	if love.keyboard.isDown("s") then
		local actualX, actualY, cols, len = world:move(mtt, self.x, self.y + self.speed * dt)
		self.x = actualX
		self.y = actualY
	end
	if love.keyboard.isDown("d") then
		local actualX, actualY, cold, len = world:move(mtt, self.x + self.speed * dt, self.y)
		self.x = actualX
		self.y = actualY
	end
end

function mtt:draw()
	love.graphics.setColor(255, 0, 0)
	love.graphics.rectangle("fill", self.x, self.y, self.w, self.h)
end

Code: Select all

-- in entity.lua

entity = {}

local entitySize = 32
local entityList = {}

function entity:load(name, x, y)
	entityList[#entityList + 1] = {name = name, x = x, y = y}
	world:add(name, x, y, entitySize, entitySize)
end

function entity:draw()
	love.graphics.setColor(0, 255, 0)
	for i = 1, #entityList do
		love.graphics.rectangle("fill", entityList[i].x, entityList[i].y, entitySize, entitySize)
	end
end
Now here's the problem the moving test thing will collide EVEN though they didn't. MTT and Entity collide even if the mtt is higher than the entity. I have no idea why :(

I'll attach the .love file if you have the time to examine it.
Thanks in advance!
User avatar
veethree
Inner party member
Posts: 875
Joined: Sat Dec 10, 2011 7:18 pm

Re: bump.lua incorrect output/input

Post by veethree »

The collision box of mtt is too tall. Probably because you put self.y instead of self.h in this line.

Code: Select all

world:add(mtt, self.x, self.y, self.w, self.y)

Here's a useful snippet for debugging such things, It draws all of bumps collision boxes.

Code: Select all

local items, len = world:getItems()
	love.graphics.setColor(255, 0, 0)
	for i,v in ipairs(items) do
		local x, y, w, h = world:getRect(v)
		love.graphics.rectangle("line", x, y, w, h)
	end
Sosolol261
Party member
Posts: 125
Joined: Wed Nov 26, 2014 6:43 am

Re: bump.lua incorrect output/input

Post by Sosolol261 »

veethree wrote:The collision box of mtt is too tall. Probably because you put self.y instead of self.h in this line.
Oh... didn't see that. THanks!!
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 89 guests