Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading documentation for HC.collisions(shape) #50

Closed
avi-0 opened this issue Aug 23, 2017 · 0 comments
Closed

Misleading documentation for HC.collisions(shape) #50

avi-0 opened this issue Aug 23, 2017 · 0 comments

Comments

@avi-0
Copy link

avi-0 commented Aug 23, 2017

The documentation says:

The separating vector points away from shape.

Example code is provided, however, it has a syntax error - no do keyword for a for loop - which could mean it hasn't ever been run. In my experience, however, it seems that the separating vector actually points towards shape. Here's some testing code:

HC = require 'HC'

radius = 25
width = 200
height = 50

function love.load()
	-- creates a circle and a rectangle so that they intersect
	shape = HC.circle(400, 300, radius)
	alsoShape = HC.rectangle(300, 315, width, height)
end

function love.keypressed(key, scancode)
	-- resolves collisions when 1 or 2 key is pressed
	if scancode == "1" then
		-- example code from HC docs, but without a syntax error
		local collisions = HC.collisions(shape)
		for other, separating_vector in pairs(collisions) do
			shape:move(-separating_vector.x/2, -separating_vector.y/2)
			other:move( separating_vector.x/2,  separating_vector.y/2)
		end
	end
	if scancode == "2" then
		-- same code, but with reversed movement
		local collisions = HC.collisions(shape)
		for other, separating_vector in pairs(collisions) do
			shape:move( separating_vector.x/2,  separating_vector.y/2)
			other:move(-separating_vector.x/2, -separating_vector.y/2)
		end
	end
end

function love.draw()
	-- draws shapes
	local x, y = shape:center()
	love.graphics.circle("line", x, y, radius)
	
	local x, y = alsoShape:center()
	love.graphics.rectangle("line", x - width / 2, y - height / 2, width, height)
end

When I press 1, shapes actually move towards each other. When I press 2, shaped move away from each other.

Initially:

test

After pressing 1:

test1

After pressing 2:

test2

@avi-0 avi-0 changed the title Misleading documentation for HC.corrections(shape) Misleading documentation for HC.collisions(shape) Aug 23, 2017
@vrld vrld closed this as completed in d64a0da Apr 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant