Hello there, fellow scripters, I’ve been trying to get this CFrame conversion to work out but i keep getting the same problem. The tank’s cannon is supposed to face the mouse direction whenever it shoots.
Here is an example of the sytem working correctly. When the body is aligned with the Z axis, it changes the C0 of the weld bellow the cannon, making it face the right direction.
But when the body rotates to another alignment (since it’s mobile) it wont work properly.
This is the code I’m currently using to get the cannon to face the right direction based on the mouse position:
local offset = rotWeld.C0 -- called before the function, so I can get the default C0.
-- Function begins --
local r = -info.plrRot -- plrRot: vector3 orientation of the HumanoidRootPart which is received by the server from a remote event that gets it locally.
local desiredCF = offset * CFrame.lookAt(plrPos, info.shootPosition).Rotation * CFrame.fromOrientation(math.rad(r.X),math.rad(r.Y),math.rad(r.Z))
game.TweenService:Create(weld, TweenInfo.new(1.5), {C0 = desiredCF}):Play()
What I tried to do here was adding the player rotation into the equation, but it seems that I’m doing something very wrong here. I’m not very proficient at CFrames, so if you can help me i’d be grateful.