Skip to content
Open
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
2 changes: 1 addition & 1 deletion dev.project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"ReplicatedStorage": {
"SmartBone": {
"$path": "src-build"
"$path": "src"
}
},

Expand Down
21 changes: 13 additions & 8 deletions src/Components/Bone.luau
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,9 @@ function Class.new(Bone: Bone, RootBone: Bone, RootPart: BasePart): IBone
Radius = 0,
Friction = 0,
RotationLimit = 0,
Force = nil,
Gravity = nil,
Force = Vector3.zero,
Gravity = Vector3.zero,
GravityFalloff = 0,

SolvedAnimatedCFrame = false,
HasChild = false,
Expand Down Expand Up @@ -585,9 +586,10 @@ function Class:StepPhysics(BoneTree, Force: Vector3, Delta: number) -- Parallel
-- Custom forces per bone
if self.Force or self.Gravity then
debug.profilebegin("Solve Force")

Force = (self.Gravity or BoneTree.Settings.Gravity)
Force += (self.Force or BoneTree.Settings.Force)

Force = (Force + (self.Force or BoneTree.Settings.Force))
debug.profileend()
end

Expand Down Expand Up @@ -710,7 +712,7 @@ function Class:SolveTransform(BoneTree, Delta: number) -- Parallel safe
--elseif ShouldAverage then
-- ParentBone.RotationSum += Vector3.new(Rotation:ToEulerAnglesXYZ())
else
ParentBone.CalculatedWorldCFrame = BoneParent.WorldCFrame:Lerp(CFrame.new(ParentBone.Position) * Rotation, alpha)
ParentBone.CalculatedWorldCFrame = ReferenceCFrame:Lerp(CFrame.new(ParentBone.Position) * Rotation, alpha)
--ParentBone.CalculatedWorldCFrame = CFrame.new(ParentBone.Position) * Rotation
end

Expand Down Expand Up @@ -744,10 +746,13 @@ function Class:ApplyTransform(BoneTree)
-- end

if ParentBone and BoneParent then
if ParentBone.Anchored and not BoneTree.Settings.AnchorsRotate then -- Anchored and anchors do not rotate
BoneParent.WorldCFrame = ParentBone.TransformOffset
elseif ParentBone.Anchored then -- Anchored and anchors rotate
BoneParent.WorldCFrame = CFrame.new(ParentBone.Position) * ParentBone.CalculatedWorldCFrame.Rotation
if ParentBone.Anchored then -- Anchored and anchors do not rotate

if BoneTree.Settings.AnchorsRotate and not self.Anchored then
BoneParent.WorldCFrame = CFrame.new(ParentBone.Position) * ParentBone.CalculatedWorldCFrame.Rotation
else
BoneParent.WorldCFrame = ParentBone.TransformOffset
end
else -- Not anchored
BoneParent.WorldCFrame = ParentBone.CalculatedWorldCFrame
end
Expand Down
21 changes: 20 additions & 1 deletion src/Components/BoneTree.luau
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type IBoneTree = {
ObjectVelocity: Vector3,
ObjectAcceleration: Vector3,
ObjectPreviousPosition: Vector3,
DefaultRootOrientation: CFrame,
}

type ImOverlay = {
Expand Down Expand Up @@ -157,6 +158,10 @@ end
--- @prop ObjectPreviousPosition Vector3
--- Root parts previous position

--- @within BoneTree
--- @prop DefaultRootOrientation
--- The Default WorldSpace Orientation of the Root Bone

local Class = {}
Class.__index = Class

Expand Down Expand Up @@ -188,6 +193,7 @@ function Class.new(RootBone: Bone, RootPart: BasePart, Settings: { any }): IBone
ObjectVelocity = Vector3.zero,
ObjectAcceleration = Vector3.zero,
ObjectPreviousPosition = RootPart.Position,
DefaultRootOrientation = (RootBone:IsA("Bone") and RootBone.WorldCFrame or CFrame.identity).Rotation,
}, Class)

self.InWorkspace = RootPart:IsDescendantOf(workspace)
Expand Down Expand Up @@ -327,7 +333,20 @@ end
function Class:StepPhysics(Delta: number)
debug.profilebegin("BoneTree::StepPhysics")
local Settings = self.Settings
local Force = (Settings.Gravity + Settings.Force)

-- Calculate the effect of Gravity given deviation from the resting 'Skyward' UpVector and clamped by GravityFalloff Setting

local DefaultRot, NewRot = self.DefaultRootOrientation.Rotation, self.Root.WorldCFrame.Rotation
local Transform = NewRot:ToWorldSpace(DefaultRot)

local RelativeDotProduct = Transform.UpVector:Dot(Vector3.yAxis)

local DistanceFromWorldUp = math.clamp(1 - RelativeDotProduct, 0, 1)

local Gravity = Settings.Gravity
Gravity = Gravity * math.lerp((1 - Settings.GravityFalloff), 1, DistanceFromWorldUp)

local Force = (Gravity + Settings.Force)

if Settings.MatchWorkspaceWind == true then
local GlobalWind = workspace.GlobalWind
Expand Down
1 change: 1 addition & 0 deletions src/Dependencies/DefaultObjectSettings.luau
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ return table.freeze({
Constraint = "Spring",
Force = Vector3.yAxis * FORCE_MULTIPLIER,
Gravity = -Vector3.yAxis * 25,
GravityFalloff = 0,

WindType = "Hybrid",
MatchWorkspaceWind = true,
Expand Down
2 changes: 1 addition & 1 deletion src/Dependencies/Utilities.luau
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function module.GatherBoneSettings(Bone: Bone)
RotationLimit = RotationLimit,
Radius = Radius,
Force = Force,
Gravity = Gravity,
Gravity = Gravity
}

return Settings
Expand Down