Page 1 of 1

I need help with bump.lua

Posted: Sat Nov 05, 2016 4:59 pm
by ElasticSpandex
So this is actually pretty embarrassing to ask. Because im sure this is extremly simple... But;
How do you offset a collision box relative to an object?
What i am trying to do it make the collisionbox half the height of the player. It has to cover the bottom half of it.

Code: Select all

collisionWorld:add(self, self.x, self.y, self.width, self.height/2) 
This obviously does what i want, it just puts the box at the top half of the player...
The obvious solution is to change the y value... Problem is, i cant.

Code: Select all

collisionWorld:add(self, self.x, self.y, self.width, self.height/2) 
--Gives the exact same result as this:
collisionWorld:add(self, self.x, self.y+self.height/2, self.width, self.height/2) 
Again, im sure the answer is very simple... So can someone please point it out for me? :awesome:

-Note: im using middleclass for objects

Re: I need help with bump.lua

Posted: Sun Nov 06, 2016 3:29 am
by kikito
The code you have shown seems correct. The problem is likely somewhere else - probably the handling of the word:move collision. But I can't know for sure without looking at the whole code. Can you upload a .love file exemplifying the problem?

Re: I need help with bump.lua

Posted: Sun Nov 06, 2016 7:27 am
by ElasticSpandex
kikito wrote:The code you have shown seems correct. The problem is likely somewhere else - probably the handling of the word:move collision. But I can't know for sure without looking at the whole code. Can you upload a .love file exemplifying the problem?
I have uploaded a .love file.
It's just your demo, where i have made line 86 match the code i wrote in my first post.

Re: I need help with bump.lua

Posted: Sun Nov 06, 2016 8:25 am
by s-ol
ElasticSpandex wrote:
kikito wrote:The code you have shown seems correct. The problem is likely somewhere else - probably the handling of the word:move collision. But I can't know for sure without looking at the whole code. Can you upload a .love file exemplifying the problem?
I have uploaded a .love file.
It's just your demo, where i have made line 86 match the code i wrote in my first post.
the offset is applied, but the first time you do world:move() it becomes 'undone' because you move the character to the wrong position relative to image.

What you need to do is not add the offset to bump.lua, but to you drawing code. So instead of trying to add the box to the lower half, just draw the charcter at self.y-self.height/2 .

If you need to use the 'visible' position of the player in more places and don't want to calculate it every time, you can instead add the offset when you do world:new() and then do it when you use world:move() too:

Code: Select all

collisionWorld:add(self, self.x, self.y+self.height/2, self.width, self.height/2) 
--
local newWorldX, newWorldY = collisionWorld:move(self, self.x, self.y+self.height/2, ...)
self.x, self.y = newWorldX, newWorldY - self.height/2
basically you need to make sure you include the offset every time you 'translate' from the 'bump coordinate system' to the 'visible coordinate system'.

Re: I need help with bump.lua

Posted: Sun Nov 06, 2016 8:57 am
by ElasticSpandex
s-ol wrote:
ElasticSpandex wrote:
kikito wrote:The code you have shown seems correct. The problem is likely somewhere else - probably the handling of the word:move collision. But I can't know for sure without looking at the whole code. Can you upload a .love file exemplifying the problem?
I have uploaded a .love file.
It's just your demo, where i have made line 86 match the code i wrote in my first post.
the offset is applied, but the first time you do world:move() it becomes 'undone' because you move the character to the wrong position relative to image.

What you need to do is not add the offset to bump.lua, but to you drawing code. So instead of trying to add the box to the lower half, just draw the charcter at self.y-self.height/2 .

If you need to use the 'visible' position of the player in more places and don't want to calculate it every time, you can instead add the offset when you do world:new() and then do it when you use world:move() too:

Code: Select all

collisionWorld:add(self, self.x, self.y+self.height/2, self.width, self.height/2) 
--
local newWorldX, newWorldY = collisionWorld:move(self, self.x, self.y+self.height/2, ...)
self.x, self.y = newWorldX, newWorldY - self.height/2
basically you need to make sure you include the offset every time you 'translate' from the 'bump coordinate system' to the 'visible coordinate system'.
Thanks! I will take a look :awesome:

--Edit: It works! Thanks again!