• 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
Junior Member
"Fresh from the Bakery"
Join Date: Sep 10, 2025
Location: your mother's abode
Posts: 10
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
 
Back
Top