a way to let kinematic collider collide with static stuff?
Posted: Sat Sep 10, 2022 5:40 pm
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