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.
The documentation says:
Example code is provided, however, it has a syntax error - no
do
keyword for afor
loop - which could mean it hasn't ever been run. In my experience, however, it seems that the separating vector actually points towardsshape
. Here's some testing code:When I press 1, shapes actually move towards each other. When I press 2, shaped move away from each other.
Initially:
After pressing 1:
After pressing 2: