Page 1 of 1

HC update error [solved]

Posted: Sun Apr 10, 2016 3:52 pm
by balloonimal
Hi! I just started checking out Löve, and was following this tutorial for HC, using version eac8874, Löve 0.10.1 and 0.9.2. I noticed a few things were deprecated (addCircle -> circle) and switched them out, and everything looks fine except that Collider:update(dt) keeps throwing the error.

Code: Select all

main.lua:73: attempt to call method 'update' (a nil value)

Traceback

main.lua:73 in function 'update'
[C]: in function 'xpcall'
I've been combing through Lua, Löve, and HC docs and can't find anything, but I'm new to this so maybe I'm just not interpreting things correctly.

Thanks for any help/explanation.

Re: HC update error

Posted: Mon Apr 11, 2016 9:08 am
by Sheepolution
It's because this is an old tutorial.

Here's the up-to-date documentation: http://hc.readthedocs.org/en/latest/

Re: HC update error

Posted: Mon Apr 11, 2016 2:10 pm
by balloonimal
I know, I said all that in the first post.

Re: HC update error

Posted: Tue Apr 12, 2016 8:38 am
by vrld
Then why do you expect the old interface to work? HC.update is no more. You have to check for collisions yourself. See also the second paragraph in the documentation that Sheepolution linked to.

Sidenote: How did you find the old documentation? That shouldn't be accessible anymore :huh:

Re: HC update error

Posted: Tue Apr 12, 2016 6:44 pm
by balloonimal
Strange, I thought I saw it. Thanks for pointing that out! In case anyone else is looking for this:

Code: Select all

collider = require('hc')

hc = collider.new(150)

function love.load()

	ball = hc:circle(400, 300, 10)
	paddleLeft = hc:rectangle(10, 250, 20, 100)
	paddleRight = hc:rectangle(770, 250, 20, 100) 
	
	ball.velocity = {x = -100, y = 0}
	
end


function love.update(dt)

	ball:move(ball.velocity.x*dt, ball.velocity.y*dt)
	
	if love.keyboard.isDown('w') then
		paddleLeft:move(0, -100*dt)
	elseif love.keyboard.isDown('s') then
		paddleLeft:move(0, 100*dt)
	end

	if love.keyboard.isDown('up') then
		paddleRight:move(0, -100*dt)
	elseif love.keyboard.isDown('down') then
		paddleRight:move(0, 100*dt)
	end

	if love.keyboard.isDown('escape') then
		love.event.push('quit')
	end

	
	local collisions = hc:collisions(ball)
	
	for other in pairs(collisions) do
		if other == goalLeft then
			ball.velocity = {x = 100, y = 0}
			ball:moveTo(400,300)
		elseif other == goalRight then
			ball.velocity = {x = -100, y = 0}
			ball:moveTo(400,300)
		elseif other == borderTop or other == borderBottom then
		
			ball.velocity.y = -ball.velocity.y
		else

			local px,py = other:center()
			local bx,by = ball:center()
			local dy = by - py			
			ball.velocity.x = -ball.velocity.x
			ball.velocity.y = dy

			
			local len = math.sqrt(ball.velocity.x^2 + ball.velocity.y^2)
			ball.velocity.x = ball.velocity.x / len * 100
			ball.velocity.y = ball.velocity.y / len * 100
		
		end
	end 

end

function love.draw()

	ball:draw('line', 16)
	paddleLeft:draw('line')
	paddleRight:draw('line')

end