I need help with bump.lua

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
ElasticSpandex
Prole
Posts: 9
Joined: Sat Nov 05, 2016 4:47 pm

I need help with bump.lua

Post 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
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: I need help with bump.lua

Post 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?
When I write def I mean function.
ElasticSpandex
Prole
Posts: 9
Joined: Sat Nov 05, 2016 4:47 pm

Re: I need help with bump.lua

Post 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.
Attachments
bumpdemp.love
(10.04 KiB) Downloaded 87 times
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: I need help with bump.lua

Post 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'.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
ElasticSpandex
Prole
Posts: 9
Joined: Sat Nov 05, 2016 4:47 pm

Re: I need help with bump.lua

Post 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!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest