So I’m making a tower defense game, and I have made a remote event to place towers.
Before you tell me to do the technique I’m already doing, here is my code:
-- 2.825 is the tower's height
-- Tower is the tower the player choosed
Tower.Joint.CFrame = CFrame.new(mousepos.X,mousepos.Y + 2.825,mousepos.Z)
Joint is the connection for the entire tower, I want it to keep the rotation of the players mouse so it faces where the player wants it to face, but this is the only way I can think of.
If you think something’s confusing in my post, lemme know because I’m tired and it’s like, 2 am, so I’m not very good at grammar right now lol
If you want to keep only the Y part of the orientation, you can do this
local CF = Mouse.Hit
local XRotation, YRotation, ZRotation = CF:ToOrientation()
CF = CFrame.new(CF.Position) * CFrame.Angles(0, YRotation, 0)
You only want to keep the YRotation, the X and Z ones are the reason it looked weird. In the code above, it’s getting the rotation of the CFrame, then making a new CFrame at the old one’s location, and then rotating it only on the Y axis.
This is the right/the simplest/the nicest looking way to do it iirc. If you add a Vector3 to a CFrame, then only its position is changed, its orientation is not.
(edit: replace CFrame.new(CF.Position) with CF)
If you really want to do do literally what’s in the post title, you’d get the CFrame’s components, modify only Y and turn it back into a CFrame.