Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/physicsutils/deploy.nevermore.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"targets": {
"test": {
"universeId": 9716264427,
"placeId": 83896797008680,
"project": "test/default.project.json",
"scriptTemplate": "test/scripts/Server/ServerMain.server.lua"
}
}
}
5 changes: 4 additions & 1 deletion src/physicsutils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
"dependencies": {
"@quenty/loader": "workspace:*",
"@quenty/maid": "workspace:*",
"@quenty/rx": "workspace:*"
"@quenty/nevermore-test-runner": "workspace:*",
"@quenty/rx": "workspace:*",
"@quenty/vector3utils": "workspace:*",
"@quentystudios/jest-lua": "3.10.0-quenty.2"
}
}
17 changes: 12 additions & 5 deletions src/physicsutils/src/Shared/PhysicsUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@
@class PhysicsUtils
]=]

local require = require(script.Parent.loader).load(script)

local Workspace = game:GetService("Workspace")

local Vector3Utils = require("Vector3Utils")

local PhysicsUtils = {}
PhysicsUtils.WATER_DENSITY = 1 -- (mass/volume)

--[=[
Retrieves all connected parts of a part, plus the connected part.
Retrieves all connected parts of a part, plus the part itself. The part appears
exactly once even though the engine already includes it in the assembly list.
@param part BasePart
@return { BasePart }
]=]
function PhysicsUtils.getConnectedParts(part: BasePart): { BasePart }
local parts: { BasePart } = part:GetConnectedParts(true) :: any
table.insert(parts, part)
if not table.find(parts, part) then
table.insert(parts, part)
end
return parts
end

Expand Down Expand Up @@ -51,7 +58,7 @@ function PhysicsUtils.estimateBuoyancyContribution(parts: { BasePart }): (number
totalFloat = totalFloat - mass * Workspace.Gravity

if part.CanCollide then
local volume = part.Size.X * part.Size.Y * part.Size.Z
local volume = Vector3Utils.volume(part.Size)
totalFloat = totalFloat + volume * PhysicsUtils.WATER_DENSITY * Workspace.Gravity
totalVolumeApplicable = totalVolumeApplicable + volume
end
Expand Down Expand Up @@ -139,7 +146,7 @@ end
@param force Vector3 -- the force vector to apply
@param forcePosition Vector3 -- The position that the force is to be applied from (World vector).
]=]
function PhysicsUtils.applyForce(part: BasePart, force: Vector3, forcePosition: Vector3)
function PhysicsUtils.applyForce(part: BasePart, force: Vector3, forcePosition: Vector3): ()
local parts = PhysicsUtils.getConnectedParts(part)

forcePosition = forcePosition or part.Position
Expand Down Expand Up @@ -170,7 +177,7 @@ end
@param emittingPart BasePart
@param acceleration Vector3
]=]
function PhysicsUtils.acceleratePart(part: BasePart, emittingPart: BasePart, acceleration: Vector3)
function PhysicsUtils.acceleratePart(part: BasePart, emittingPart: BasePart, acceleration: Vector3): ()
local force = acceleration * part:GetMass()
local position = part.Position

Expand Down
Loading
Loading