Pixel Art Game - Raycast Skipping Pixels Issue

Hey everyone,

I’m working on a pixel art game using raycasts, but I’ve run into an issue. When moving the mouse quickly across the screen, the raycast seems to skip pixels, as shown in this video:

I’m already using RenderStepped, so I’m not sure how to make it more accurate. Here’s my current code:

rs.RenderStepped:Connect(function(dt)
    if not InGame.Value or not clicked then return end

    local raycastParams = RaycastParams.new()
    local raycast = workspace:Raycast(mouse.UnitRay.Origin, mouse.UnitRay.Direction * 1000, raycastParams)

    if not raycast then return end

    local rayInstance = raycast.Instance
    if rayInstance.Parent.Name ~= "PixelGrid" then return end

    rayInstance.Color = Color3.new(0, 0, 0)
end)

I’m guessing the issue happens because the mouse moves too far between frames, causing some pixels to be missed. Does anyone know a better way to ensure all pixels get updated, even when moving the mouse quickly?

Any help would be greatly appreciated! Thanks

1 Like

Hi,

One solution would be to calculate the data interpolation between the last and new points to predict where these skipped pixels are, there should be many videos and resources online to aid you - if you do need any help finding some then let me know. Since we’re running it off RenderStepped, there is an insignificance in accuracy loss and most software incorporates this method.

There are many other solutions, but I believe this would be beneficial without causing performance-related issues.

4 Likes

yes i just thought of this solution and will look more into it, thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.