I am working on a physics object carrying system, and have found myself dumbfounded.
As seen in the video, after picking up the object, turning the character does not change the orientation of the object being carried. I would like to make it so the orientation of the object does not change relative to the character.
Any help is appreciated, thank you!
The relevant code snippet:
local function registerCarry(model:Model)
local part = model.PrimaryPart
local Root = getRoot()
if part and Root and part.AssemblyMass <= 10000 then
Remote:FireServer("Pickup",model)
Pos = Instance.new("BodyPosition",part)
Pos.MaxForce = Vector3.new(50000,50000,50000)
Pos.D = 500
Gyro = Instance.new("BodyGyro",part)
Gyro.MaxTorque = Vector3.new(50000,50000,50000)
Gyro.CFrame = part.CFrame
local RootOffset = BaseRootOffset * (part.Size / 2)
RootConnection = RunS.Heartbeat:Connect(function()
local rootPos = Root.Position
Pos.Position = Root.CFrame:PointToWorldSpace(RootOffset)
if (part.Position - rootPos).Magnitude > MaxDistance or part.Position.Y - rootPos.Y < -2 or (Root.CFrame:Inverse() * part.CFrame).Z > 0 then
dropObject()
end
end)
end
end
Get the current lookvector,upvector and rightvector then use cframe.fromMatrix() to apply only the root position along with the orientation from the 3 vectors.
local Distance = 2 --you can edit this
local Part = path to your part
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local hrp = Character.HumanoidRootPart
RunService.RenderStepped:Connect(function()
Part.CFrame = hrp.CFrame + hrp.CFrame.LookVector*Distance
end)
I don’t think he wants the part’s orientation to be the same as the hrp, but maintain it’s orientation when picked up and only rotate when the player rotate.
He wants the “object orientation relative to” the hrp, meaning on screen when you are carrying it, the object does not seem to be rotating unless viewed from another perspective.