a way to let kinematic collider collide with static stuff?

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
sneakywinnie
Prole
Posts: 2
Joined: Sat Sep 10, 2022 4:54 pm

a way to let kinematic collider collide with static stuff?

Post 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
User avatar
togFox
Party member
Posts: 828
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

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

Post by togFox »

I assume you're using a physics library of some sort?
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Turn-based PBEM horse stable (racing) management sim: https://togfox.itch.io/horse-stable-manager
https://discord.gg/HeHgwE5nsZ
Ross
Party member
Posts: 100
Joined: Tue Mar 13, 2018 12:12 pm
Contact:

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

Post 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.
sneakywinnie
Prole
Posts: 2
Joined: Sat Sep 10, 2022 4:54 pm

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

Post 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!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], swuare and 4 guests