What's wrong with this bounding box?

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
luaz
Citizen
Posts: 83
Joined: Sun Sep 16, 2012 2:55 pm

What's wrong with this bounding box?

Post by luaz » Sun Sep 30, 2012 6:57 pm

I'm using Hardon Collider, but I think it's something in my code instead.

Here's my code, with function names nearby:

Code: Select all

	.load()
	player.colRect = col:addRectangle(player.x, player.y, player.width, player.height)
	-- .update(dt)
	-- I have to add player.width / 2 for some reason, otherwise the bounding rectangle is drawn not right under the sprite.
	player.colRect:moveTo(player.x + player.width / 2, player.y + player.height / 2)
The image below illustrates the problem I'm talking about.

Image

While the collision works, is detected, etc., when the key is held down, the sprite moves a bit into the sprite it's colliding with. It's explainable by the fact that the colliding box isn't moving, however it allows the sprite to move, even though it shouldn't, as it uses the same position variables as the sprite.

Just in case, here's what I do if the shapes collide: player.x = 128 - player.width (128 is the X position of the test sprite)

P.S. I think this can be solved without attaching .love.
If you're going to reply to my post, consider posting an (preferably working) example - 99.7% of time time, I already know how to implement the feature theoretically! ;) I don't learn very well from references, etc....

User avatar
qaisjp
Party member
Posts: 490
Joined: Tue Sep 04, 2012 10:49 am
Location: United Kingdom
Contact:

Re: What's wrong with this bounding box?

Post by qaisjp » Sun Sep 30, 2012 7:08 pm

Only move the bounding box, and draw the bricks relative to the bounding box. This way if the bounding box doesn't move, then the texture brick won't.
Lua is not an acronym.

luaz
Citizen
Posts: 83
Joined: Sun Sep 16, 2012 2:55 pm

Re: What's wrong with this bounding box?

Post by luaz » Sun Sep 30, 2012 7:11 pm

qaisjp wrote:Only move the bounding box, and draw the bricks relative to the bounding box. This way if the bounding box doesn't move, then the texture brick won't.
I move the bounding box as player.x, and I set the sprite's x to player.x as well. Technically, they are both moving, but if one can't move, so can't the other. I don't see a problem here. What exactly are you suggesting?
If you're going to reply to my post, consider posting an (preferably working) example - 99.7% of time time, I already know how to implement the feature theoretically! ;) I don't learn very well from references, etc....

User avatar
qaisjp
Party member
Posts: 490
Joined: Tue Sep 04, 2012 10:49 am
Location: United Kingdom
Contact:

Re: What's wrong with this bounding box?

Post by qaisjp » Sun Sep 30, 2012 7:12 pm

luaz wrote:
qaisjp wrote:Only move the bounding box, and draw the bricks relative to the bounding box. This way if the bounding box doesn't move, then the texture brick won't.
I move the bounding box as player.x, and I set the sprite's x to player.x as well. Technically, they are both moving, but if one can't move, so can't the other. I don't see a problem here. What exactly are you suggesting?
Sorry, I misread.

Regardless it seems you are using Hardoncollider incorrectly.
Lua is not an acronym.

SudoCode
Citizen
Posts: 61
Joined: Fri May 04, 2012 7:05 pm

Re: What's wrong with this bounding box?

Post by SudoCode » Sun Sep 30, 2012 7:16 pm

Try shape:move(x,y) and draw the sprite based on that.

luaz
Citizen
Posts: 83
Joined: Sun Sep 16, 2012 2:55 pm

Re: What's wrong with this bounding box?

Post by luaz » Sun Sep 30, 2012 7:19 pm

qaisjp wrote:Regardless it seems you are using Hardoncollider incorrectly.
That's what I thought. Could you give me an example on how I should be using it?
SudoCode wrote:Try shape:move(x,y) and draw the sprite based on that.
I just tried it before reading your post, same results. ;)
If you're going to reply to my post, consider posting an (preferably working) example - 99.7% of time time, I already know how to implement the feature theoretically! ;) I don't learn very well from references, etc....

SudoCode
Citizen
Posts: 61
Joined: Fri May 04, 2012 7:05 pm

Re: What's wrong with this bounding box?

Post by SudoCode » Sun Sep 30, 2012 7:21 pm

You should post the entire .love then. If the sprite is being draw based on the position of the player shape, it should not desync at all.

luaz
Citizen
Posts: 83
Joined: Sun Sep 16, 2012 2:55 pm

Re: What's wrong with this bounding box?

Post by luaz » Sun Sep 30, 2012 9:18 pm

SudoCode wrote:You should post the entire .love then. If the sprite is being draw based on the position of the player shape, it should not desync at all.
It's syncing now, turns out update sequence matters.

Anyway, I'm still curious on how I should use HC if I'm using it wrong.
If you're going to reply to my post, consider posting an (preferably working) example - 99.7% of time time, I already know how to implement the feature theoretically! ;) I don't learn very well from references, etc....

User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: What's wrong with this bounding box?

Post by vrld » Mon Oct 01, 2012 6:42 pm

luaz wrote:

Code: Select all

	.load()
	player.colRect = col:addRectangle(player.x, player.y, player.width, player.height)
	-- .update(dt)
	-- I have to add player.width / 2 for some reason, otherwise the bounding rectangle is drawn not right under the sprite.
	player.colRect:moveTo(player.x + player.width / 2, player.y + player.height / 2)
See the documentation for HC:addRectangle() and shape:moveTo():
function HC:addRectangle(x, y, w, h) wrote:Note: Shape transformations, e.g. shape:moveTo() and shape:rotate(), will be with respect to the rectangle center, not the upper left corner.
function shape:moveTo(x, y) wrote:Important: This function moves the shape's center to (x,y). [...]
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine

Post Reply

Who is online

Users browsing this forum: No registered users and 38 guests