- What do you want to achieve?
I am making a custom inventory system where the tool’s models are welded to the character separately.
- What is the issue?
When I try setting the CFrame of C1, the orientation doesn’t get set to the desired Vector3.
- What solutions have you tried so far?
I have tried manually calculating radians as well as
math.rad(). I also tried using Motor6D instead of weld.
If it wasn’t clear enough before, I am using angles to set the orientation.
Here is the relevant code:
ModelWeld.C1 = CFrame.new(Vector3.new(0, -0.65, 0)) * CFrame.Angles(270*(math.pi/180),22.5*(math.pi/180),0)
ModelWeld.Part0 = Character.Torso
i think you need to declare the Part1 of the weld
That is done before the script.
You’ll want to create a weld that’s relative to the position of
Character.UpperTorso, using the
VectorToWorldSpace function. See the below snippet on how to use this function.
local Players: Players = game:GetService("Players")
local tool: Tool = script.Parent
local backpack = tool.Parent
local player: Player = backpack.Parent
local character = player.Character or player.CharacterAdded:Wait()
-- create new weld
local weld = Instance.new("Weld")
weld.Parent = tool.Handle
-- delay a bit since tool hasn't finished reparenting to Backpack
tool.Parent = character.UpperTorso
-- setting these after parenting will update weld correctly in the world
local left = 0
local down = 0
local forward = 2
weld.C1 = CFrame.new(character.UpperTorso.CFrame:VectorToWorldSpace(Vector3.new(left, down, forward)))
weld.Part1 = tool.Handle
weld.Part0 = character.UpperTorso
IdleAnimTrack = Character.Humanoid:LoadAnimation(IdleAnim)
ModelWeld.C1 = CFrame.new(Vector3.new(0, 0.65, 0)) * CFrame.Angles(0,0,0)
ModelWeld.Part0 = Character["Right Arm"]
I’m not sure if it’s the way I’m calculating the angle or if it’s something else.
The problem is that the
CFrame.Angles function does not work in the way you are expecting.
CFrame.Angles takes in three numbers, one for each axis (x, y and z). These numbers are in radians, not degrees.
So a rotation of 90 degrees around the x axis would be (1.5708, 0, 0).
The correct code would be:
CFrame.new(Vector3.new(0, -0.65, 0)) * CFrame.Angles(1.5708, 0.383972, 0)
That is what math.pi/ or math.rad() does.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.