jaipack17 / Nature2D

A 2D physics engine for Roblox. Create versatile physics simulations and mechanics with GUIs!
https://jaipack17.github.io/Nature2D/
MIT License
147 stars 8 forks source link

Collisions break if body goes outside the viewport #50

Open jammees opened 10 months ago

jammees commented 10 months ago

Noticed that collisions suddenly stop working and bodies start going through each other if they are outside of the viewport.

Reproduction Steps

  1. Create a "Ground" body, which is Collidable and Anchored and is positioned in the center of the screen and has a size of UDim2.new(3, 0, 0, 50)
  2. Create another body, which is Collidable and has KeepInCanvas set to false and is positioned at UDim2.new(0.99, 0, 0, 0)
  3. Start the simulation
  4. Notice that the body we created in the second step just phased through the Ground body

Expected Behavior

Rigidbodies should always have collisions no matter if they are visible on the screen or not

Actual Behavior

Rigidbodies go through each other

Media

Scene file:

---@module src.init
local Rethink = require(game:GetService("ReplicatedStorage").Rethink)
local Modules = Rethink.GetModules()
local Scene = Modules.Scene
local Symbols = Scene.Symbols

return {
    Name = "nature2D_bug_report.scene",

    Rigidbodies = {
        [Symbols.Type] = "Rigidbody",

        Ground = {
            AnchorPoint = Vector2.new(0.5, 0),
            Position = UDim2.new(0.5, 0, 1, -50),
            Size = UDim2.new(3, 0, 0, 50),
            BackgroundColor3 = Color3.fromRGB(126, 126, 126),

            [Symbols.Rigidbody] = {
                Anchored = true,
                Collidable = true,
            },
        },

        Body = {
            Size = UDim2.fromOffset(100, 100),
            Position = UDim2.new(0.99, 0),

            [Symbols.Rigidbody] = {
                Collidable = true,
                KeepInCanvas = false,
            },
        },
    },
}

https://github.com/jaipack17/Nature2D/assets/86011536/eaffea2b-7287-45dd-9424-1dfb7a21c62c

jammees commented 10 months ago

After trying to find out why the problem occurs I decided to turn off QuadTrees. After that I had ran the same simulation and noticed that the body did collide with the ground but the ground's rigidbody is not as big as the frame itself but rather the screen's widht.