Rotating Tool With Respect to Part's Orientation

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)

Thanks! :smiley:

1 Like

Perhaps something like this would work for you.

local podiumTop = Podium.Position + Vector3.new(0, Podium.Size.Y/2, 0)
local handleHeight = Prize.Handle.Size.Y
local gripOffset = Prize.Grip.Position

local offset = Vector3.new(0, handleHeight/2 + gripOffset.Y, 0) - Vector3.new(0, 1.25, 0)
local finalCFrame = CFrame.new(podiumTop + offset) * Podium.CFrame.Rotation

Prize.Handle.CFrame = finalCFrame

or

local podiumTop = Podium.Position + Vector3.new(0, Podium.Size.Y/2, 0)

local offset = -Vector3.new(0, 1.25, 0)
local finalCFrame = CFrame.new(podiumTop + offset) * Podium.CFrame.Rotation * Prize.Grip:Inverse()

Prize.Handle.CFrame = finalCFrame

I didn’t really understand what you meant by “offsetting it by the Tool’s grip offset,” but if this helped then cool

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

Podium.CFrame:ToWorldSpace(CFrame.new(0, Podium.Size.Y/2, 0)):ToWorldSpace(CFrame.new(0, 1.25, 0))

instead

The code above correctly positions prizes on the podiums for a display system as show below:

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.

1 Like

add something like

Prize.Handle.CFrame = Prize.Handle.CFrame:ToWorldSpace(CFrame.Angles(  0, math.rad(180), math.rad(90)  ))

at the very end of the script to rotate it by 90 and 180 degrees. Switch the order of them until its rotated correctly

While this would work for the teddy bear, it wouldn’t universally work for other prizes with different orientations.

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) )

The problem with this solution is that I would have to do this for 80-100 prizes.

Is it impossible to access the grip orientation and then apply it to the Tool’s orientation?

https://create.roblox.com/docs/reference/engine/classes/Tool#Grip

You might be able to use this. You can use CFrame.Rotation to return a cframe with only the orientation, and then apply it like this

Prize.Handle.CFrame = Prize.Handle.CFrame:ToWorldSpace(Prize.Grip.Rotation)

It might always be rotated sideways depending on the orientation of the podium part, or it might rotate it in the opposite direction

useful cframe methods are
CFrame:Inverse()
and CFrame:ToWorldSpace()
which you can apply if every prize ends up offset in the same way

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.