I am trying to place a Prize (a Tool with a Handle MeshPart parented to it) on top of a Podium (a cylinder Part) by sitting the Prize on top of the Podium and then rotating it with respect to the Podium’s orientation.
However, I am having issues setting the Prize’s orientation to the Podium’s orientation, and then offsetting it by the Tool’s grip orientation. The tool’s grip cannot be changed or else it will be rotated incorrectly when reequipped by a player, so I’d have to rotate its Handle. How can I change the code below in order to achieve this?
local podiumTop = Podium.Position + Vector3.new(0, Podium.Size.Y/2, 0)
local handleHeight = Prize.Handle.Size.Y
local gripOffset = Prize.Grip.Position
local PX, PY, PZ = Podium.CFrame:ToOrientation()
local GX, GY, GZ = Prize.Grip:ToOrientation()
local finalCFrame = CFrame.new(podiumTop + Vector3.new(0, handleHeight/2 + gripOffset.Y, 0)) * CFrame.Angles(PX, PY, PZ)
local adjustedPosition = finalCFrame.Position - Vector3.new(0, 1.25, 0)
Prize.Handle.CFrame = CFrame.new(adjustedPosition, adjustedPosition + finalCFrame.LookVector)
If I want to change a tool’s grip if it’s held incorrectly, I can use its grip orientation property. I’m trying to recreate this for a part instead of a player.
“Rotation Tool With Respect to Part’s Orientation” reminds me of CFrame_Base:ToWorldSpace(CFrame_Offset)
which is different from just adding two positions and two orientations together.
If the tool is sitting on the podium and the player picks it up by touching it, could you replace this pick-up method with something else, like a clickdetector? Instead of having the actual tool sitting on the podium, you could have just the mesh (outside of a tool), with a script that removes the stationary mesh when it is clicked, and gives the actual tool (in ReplicatedStorage or elsewhere) to the character.
If you can’t or don’t want to do the above, what is the current behavior? I think you could simplify the code to remove the PX, PY, PZ, GX, GY, GZ variables and use
The problem is with prizes with custom orientations, like the teddy bear. I’m trying to use the tool grip orientation data to adjust the prize to face the correct way.
You could create a CFrameValue inside of the teddy bear tool and name it something like “PrizeOffset”
and use
local PrizeOffset = Prize:FindFirstChild("PrizeOffset")
if PrizeOffset then
Prize.Handle.CFrame = Prize.Handle.CFrame:ToWorldSpace(PrizeOffset.Value)
end
I think that would be a little more difficult to fine-tune the CFrame values in the properties panel, but it could be done by writing this in the console line:
Prize.PrizeOffset.Value = CFrame.Angles(0, CFrame.Angles(180), CFrame.Angles(90) )