• Please stop embedding files/images from Discord. Discord has anti-hotlinking logic in place that breaks links to Discord hosted files and images when linked to from anywhere outside of Discord. There are a multitude of file/image hosting sites you can use instead.

    (more info here)

Collision detection help?

Jan 2, 2026 at 7:15 PM
Neophyte Member
"Fresh from the Bakery"
Join Date: Sep 10, 2025
Location: your mother's abode
Posts: 9
Posting this in the modding discussion instead: I was attempting to change the knife into a close range weapon that pushes the player back when they are hitting an enemy or entity. currently it just pushes the player, which is progress, but it just allows them to fly due to allowing the hit to be registered regardless of if it's hitting an enemy or not. more specifically, i want the player to be pushed back when they hit an enemy. here is the code:

Code:
ModCS.Bullet.Act[25] = function(bul)
 
    bul.count1 = bul.count1 + 1
    if bul.count1 > bul.life_count then -- life_count is the "frames to live" in bullet properties
        
        ModCS.Bullet.Delete(bul)
        ModCS.Caret.Spawn(3, bul.x, bul.y, 0) -- Spawn effect 3 (shoot effect)
        return
    end

  
    if bul.count1 == 3 then
        ModCS.Bullet.UnsetBit(bul, 3) -- 2 is the "ignore solid" bit
    end

    -- Play a sound every so often
    if bul.count1 % 1 == 1 then
        ModCS.Sound.Play(12)
    end

 
    if bul.act_no == 0 then
        bul.act_no = 1
        -- Set movement velocity
        if bul.direct == 0
         then-- left -- 4 px/frame
            ModCS.Player.xm = 1112
            ModCS.Player.ym = -812
        elseif bul.direct == 1 then -- up
            bul.ym = -1
        elseif bul.direct == 2 then -- right
            bul.xm = 1
        elseif bul.direct == 3 then -- down
            bul.ym = 1
            ModCS.Player.ym = -1112
        else
        ModCS.Player.ym = 0 ModCS.Player.xm = 0
    end
        -- Move the bullet
        if ModCS.Player.direct == 0 then
            bul.x = -20 + ModCS.Player.x
            bul.y = ModCS.Player.y
        elseif ModCS.Player.direct == 2 then
            bul.x = 20 + ModCS.Player.x
            bul.y = ModCS.Player.y
        end

        local left_animation_frames = {
            ModCS.Rect.Create(0, 48, 16, 64),
            ModCS.Rect.Create(16, 48, 32, 64),
            ModCS.Rect.Create(32, 48, 48, 64),
            ModCS.Rect.Create(48, 48, 64, 64)
        }
        local right_animation_frames = {
            ModCS.Rect.Create(64, 48, 80, 64),
            ModCS.Rect.Create(80, 48, 96, 64),
            ModCS.Rect.Create(96, 48, 112, 64),
            ModCS.Rect.Create(112, 48, 128, 64)
        }

        -- Animate the bullet
        bul.ani_wait = bul.ani_wait + 1
        if bul.ani_wait > 1 then
            bul.ani_wait = 0
            bul.ani_no = bul.ani_no + 1
        end
        if bul.ani_no > 3 then
            bul.ani_no = 0
        end

        if bul.direct == 0 then
            ModCS.Bullet.SetRect(bul, left_animation_frames[bul.ani_no + 1])
        else
            ModCS.Bullet.SetRect(bul, right_animation_frames[bul.ani_no + 1])
        end
    end
end
 
Jan 3, 2026 at 7:35 AM
Senior Member
"This is the greatest handgun ever made! You have to ask yourself, do I feel lucky?"
Join Date: May 18, 2024
Location: First Cave
Posts: 91
Pronouns: He/him
Gender Notes: Cats are fluffy beings, this therefore makes them aliens.
My best guess to detect if it's hitting an enemy would be utilizing the shootable flag since most enemies you come across in-game are shootable. I'd also recommend using an 'if () then' statement, so in other words it'd be like: if (Entity.flag.shootable == true) then push the player back. If you're talking about Entities in general I'd just add "Entity != NULL" since if it's not null then there's an entity there.

I don't know much about Lua code but I hope this helps in some way.
 
Last edited:
Jan 4, 2026 at 10:40 PM
Neophyte Member
"Fresh from the Bakery"
Join Date: Sep 10, 2025
Location: your mother's abode
Posts: 9
tysm for you help :D
 
Back
Top