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

FPS Unlocker causes physics issues #37

Closed Cryisaguy closed 2 years ago

Cryisaguy commented 2 years ago

As the title says, FPS unlocker seems to mess with certain physics features such as friction, gravity and possibly other physics-based things as well. At 60 fps, friction behaves expectedly but setting the fps cap to none causes issues in which friction seems to be instantaneous and also causes gravity to be stronger.

Reproduction Steps

The FPS Unlocker being used is created by axstin. Using :ApplyForce() with the fps cap set to none.

Code utilized below:

local Nature2D = require(script:WaitForChild("Nature2D"))

local Viewport = workspace.CurrentCamera.ViewportSize
local Canvas = script.Parent:FindFirstChild("Canvas")

local Engine = Nature2D.init(script.Parent)
Engine:CreateCanvas(Vector2.new(), Viewport, Canvas)

local Floor = Engine:Create("RigidBody", {
    Object = Canvas.Ground,
    Collidable = true,
    Anchored = true
})

local Object = Engine:Create("RigidBody", {
    Object = Canvas.Object,
    Collidable = true,
    Anchored = false
})

Object:CanRotate(false)
Engine:Start()

local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.E then
        Object:ApplyForce(Vector2.new(50, 0), 1)
    end

    if Input.KeyCode == Enum.KeyCode.F then
        Object:ApplyForce(Vector2.new(0, -50), 1)
    end
end)

Expected Behavior

For friction and gravity to behave similar to how they behave at 60 fps.

Actual Behavior

Friction seemed to be instantaneous instead of being smooth, and gravity seems to be normal.

Media

Behavior with 60 fps cap:

60fpscap

Behavior with no fps cap:

NoCap

Lastly

I'm not sure what else this may possibly affect, but I just wanted to notify incase it also shows other issues that fps unlocker may cause. Sorry if this isn't very informative, it's my first bug report.

jaipack17 commented 2 years ago

Thank you for reporting! I'll work on it. I think the problem lies within how I am using deltaTime.

jaipack17 commented 2 years ago

Thank you for the patience! This has been fixed in #38

Will release v0.7.1 tomorrow after completing the documentation and testing the new updates. If you want to try the fix early though, you can clone the pr-bug-fixes branch from this repository. Thanks!

Edit: Released v0.7.1