Issue using Hardon Collider
Posted: Thu Feb 16, 2017 9:57 pm
I am having this silly issue with my collisions. I chose this library HC to detect collisions, but there's not a lot of actual examples of it in use anywhere that i can find in order to reverse engineer. Has anyone used this library?
this is what my code looks like:
now obviously, when the shapes collide it turns this boolean off breaking my movement code. but i cant seem to figure out any other way to have my stuff stop moving when it collides. This is an amateurish problem to be having, but i'm pretty new to love2d. I'm not using tile-maps or anything like that, i'm just trying to effect collision between these two shapes. What am i missing?
this is what my code looks like:
Code: Select all
require "AnimatedSprite"
HC = require 'hardoncollider'
Polygon = require 'hardoncollider.polygon' --Including the file
diag = 0
collide = false
x = 400
y = 400
function love.load()
love.graphics.setDefaultFilter("nearest", "nearest")
player = GetInstance ("player.lua")
level = GetInstance ("level.lua")
subject = GetInstance ("subject.lua")
beam = GetInstance ("beam.lua")
emitter = HC.circle(400,300,20)
poly = HC.polygon(10,35, 40,50, 70,35, 40,20)
poly:moveTo(x+25,y+80)
end
function love.update(dt)
love.mouse.setVisible(false)
UpdateInstance(player, dt)
UpdateInstance(level, dt)
UpdateInstance(beam, dt)
UpdateInstance(subject, dt)
poly:moveTo(x+25,y+80)
for shape, delta in pairs(HC.collisions(poly)) do
collide=true
end
if collide == false then
if(love.keyboard.areDown('s','a')) then
y=y+dt+0.83
x=x-dt-1.7
player.curr_anim = player.sprite.animations_names[4]
diag = 1
frozen=false
elseif(love.keyboard.areDown('s','d')) then
y=y+dt+0.83
x=x+dt+1.7
player.curr_anim = player.sprite.animations_names[10]
diag=2
elseif(love.keyboard.areDown('w','a')) then
y=y-dt-0.83
x=x-dt-1.7
player.curr_anim = player.sprite.animations_names[6]
diag=3
elseif(love.keyboard.areDown('w','d')) then
y=y-dt-0.83
x=x+dt+1.7
player.curr_anim = player.sprite.animations_names[8]
diag=4
elseif(love.keyboard.isDown('w')) then
y=y-dt-1.6
player.curr_anim = player.sprite.animations_names[7]
diag=0
elseif(love.keyboard.isDown('a')) then
x=x-dt-1.6
player.curr_anim = player.sprite.animations_names[5]
elseif(love.keyboard.isDown('s')) then
y=y+dt+1.6
diag=0
player.curr_anim = player.sprite.animations_names[3]
elseif(love.keyboard.isDown('d')) then
x=x+dt+1.6
player.curr_anim = player.sprite.animations_names[9]
end
end
end