Hardon Collider Trouble

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.
Post Reply
BigWig
Prole
Posts: 1
Joined: Sat Mar 01, 2014 5:28 am

Hardon Collider Trouble

Post by BigWig »

Scenario: Two rectangles falling at the same speed, how do I get them to both collide with the ground and stop? Here is my code:

Code: Select all

HC = require 'hardoncollider'

function on_collide_2(dt, shape_a, shape_b)
    local other
    if shape_a == player_1 then
        other = shape_b
    elseif shape_b == player_1 then
        other = shape_a
    else
        return
    end
    if other == ground then
        on_ground = true
        print("JLKSFJ")
    end
end
function on_collide(dt, shape_a, shape_b)
    local other
    if shape_a == player_2 then
        other = shape_b
    elseif shape_b == player_2 then
        other = shape_a
    else -- no shape is the ball. exit
        return
    end
    if other == ground then
        on_ground_2 = true
--         print("JLKSFJ")
    end
end
function love.load()
    Collider = HC(100,  on_collide, on_collide_2)
    grav = 0
    grav_2 = 0
    on_ground = false
    on_ground_2 = false
    player_1 = Collider:addRectangle(500, 251, 20, 100)
    player_2 = Collider:addRectangle(770, 250, 20, 100)
    ground = Collider:addRectangle(20, 400, 800, 100)
end

function love.update(dt)
    Collider:update(dt)
    if on_ground == false then
        grav = (9.8 * dt^2)*500
    else
        grav = 0
    end
    if on_ground_2 == false then
        grav_2 = (9.8 * dt^2)*500
    else 
        grav_2 = 0
    end
    player_1:move(0, grav)
    player_2:move(0, grav_2)
end

function love.draw()
    player_1:draw('fill')
    player_2:draw('fill')

end
User avatar
alberto_lara
Party member
Posts: 372
Joined: Wed Oct 30, 2013 8:59 pm

Re: Hardon Collider Trouble

Post by alberto_lara »

Hi, BIgWig, the better way it's to put a .love file :)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 7 guests