Page 1 of 1

a way to let kinematic collider collide with static stuff?

Posted: Sat Sep 10, 2022 5:40 pm
by sneakywinnie
I set the type of bullets to be 'kinematic',ground and walls 'static'.I know that kinematic bodies only collide with dynamic bodies,is there a way to change that?Or if I set bullets to be dynamic,they immediately drop into the ground when I shoot,I set the mass of them to be 0,it turns out that doesn't work,is there a way to make it work?

Code: Select all

--bullet.lua
function Bullet:update(dt)  
    cd=cd-dt*2
    if love.keyboard.isDown('space') and cd<=0 then
        cd=cd+1
        local vx=0
        if facingL then
            vx=bullet.spd*-1
        else
            vx=bullet.spd
        end
        B=world:newCircleCollider(player.x+35,player.y+30,w*1/2)
        B:setMass(0)
        B:setLinearVelocity(vx,0)
        B:setType('kinematic')
        B:setCollisionClass('bullet')
        Bullet={x=player.x+15,y=player.y+20,vx=vx,B=B}
        table.insert(bullets,Bullet)
        cd=math.max(cd,0)     
        local m=B:getMass()
        print(m)
    end
    


for i,v in ipairs(bullets) do 
    v.x=v.x+v.vx*dt
    if v.x<0 or v.x>1550 or v.B:enter('ground')then
        table.remove(bullets,i)
        v.B:destroy()   
    end
end
end

Re: a way to let kinematic collider collide with static stuff?

Posted: Sun Sep 11, 2022 1:29 am
by togFox
I assume you're using a physics library of some sort?

Re: a way to let kinematic collider collide with static stuff?

Posted: Sun Sep 11, 2022 12:06 pm
by Ross
I don't think so, not without modifying Box2D and recompiling Löve anyway.

If you don't want a dynamic body to be affected by gravity, you can use Body:setGravityScale (set it to zero).

You can also make the bullets sensors (Fixture:setSensor) if you just need basic collision detection.

Re: a way to let kinematic collider collide with static stuff?

Posted: Mon Sep 12, 2022 8:20 am
by sneakywinnie
Ross wrote: Sun Sep 11, 2022 12:06 pm I don't think so, not without modifying Box2D and recompiling Löve anyway.

If you don't want a dynamic body to be affected by gravity, you can use Body:setGravityScale (set it to zero).

You can also make the bullets sensors (Fixture:setSensor) if you just need basic collision detection.
That works,thanks a lot!