Hardon Collider Help

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.
Ethan-Taylor
Prole
Posts: 34
Joined: Mon Nov 24, 2014 9:15 pm

Re: Hardon Collider Help

Post by Ethan-Taylor »

FruityLark wrote:In your custom border collision code, you are dividing the circle radius by 2 as if it were the diameter. There will be no shape intersection if you use 30 (half the width of your circle) instead of 30/2.

Also you should have player:draw('line') instead of player:draw('line',50) on main.lua:103
Ahh I see, so the value of 30 is the radius, not the diameter. Thank you.
Ethan-Taylor
Prole
Posts: 34
Joined: Mon Nov 24, 2014 9:15 pm

Re: Hardon Collider Help

Post by Ethan-Taylor »

Muzz wrote:I did, the wall collision worked fine?
Don't worry I've fixed it now.
But from this another problem has arised.
The collision with the sqaure is also offset.
User avatar
FruityLark
Prole
Posts: 28
Joined: Sat Jun 13, 2015 8:18 pm

Re: Hardon Collider Help

Post by FruityLark »

Since the square is a collider shape, you need to fix the onCollide function.
When you fix this, you will have an interesting situation where the ball jumps to the other side of the square as you continue to force the camera past the square.

Code: Select all

function onCollide(dt, shape_a, shape_b, dx, dy)
if shape_a.type == "player" then
	--movement.yvel = 0
	--movement.xvel = 0
	shape_a:move(dx, dy)
end
end
Ethan-Taylor
Prole
Posts: 34
Joined: Mon Nov 24, 2014 9:15 pm

Re: Hardon Collider Help

Post by Ethan-Taylor »

FruityLark wrote:Since the square is a collider shape, you need to fix the onCollide function.
When you fix this, you will have an interesting situation where the ball jumps to the other side of the square as you continue to force the camera past the square.

Code: Select all

function onCollide(dt, shape_a, shape_b, dx, dy)
if shape_a.type == "player" then
	--movement.yvel = 0
	--movement.xvel = 0
	shape_a:move(dx, dy)
end
end
How do I calculate dx and dy?
The player just seems to go right past the sqaure
User avatar
FruityLark
Prole
Posts: 28
Joined: Sat Jun 13, 2015 8:18 pm

Re: Hardon Collider Help

Post by FruityLark »

Declare your onCollide function exactly the same as I showed, and you can just use them.
HC provides these values (dx, dy) for you to resolve the collision.

You also need to add the property 'type' or 'name' or whatever to your player shape, else the if statement in onCollide won't fire.

Code: Select all

player = collider:addCircle(movement.x, movement.y, 30)
player.type = "player"
Ethan-Taylor
Prole
Posts: 34
Joined: Mon Nov 24, 2014 9:15 pm

Re: Hardon Collider Help

Post by Ethan-Taylor »

FruityLark wrote:Declare your onCollide function exactly the same as I showed, and you can just use them.
HC provides these values (dx, dy) for you to resolve the collision.

You also need to add the property 'type' or 'name' or whatever to your player shape, else the if statement in onCollide won't fire.

Code: Select all

player = collider:addCircle(movement.x, movement.y, 30)
player.type = "player"
Hmm, still the problem ...

Image

Code: Select all

function onCollide(dt, a, b, dx, dy)
	if a.type == "player" then
	--	movement.yvel = 0
	--	movement.xvel = 0
		a:move(dx,dy)
	end
end
Everything else is working fine.
User avatar
FruityLark
Prole
Posts: 28
Joined: Sat Jun 13, 2015 8:18 pm

Re: Hardon Collider Help

Post by FruityLark »

I can't see what you're missing without the code. Try the attached version.
Attachments
game-updated.love
(117.62 KiB) Downloaded 69 times
Ethan-Taylor
Prole
Posts: 34
Joined: Mon Nov 24, 2014 9:15 pm

Re: Hardon Collider Help

Post by Ethan-Taylor »

FruityLark wrote:I can't see what you're missing without the code. Try the attached version.
just set the velocity to 0 now?
Post Reply

Who is online

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