Hello, I’m trying to make a model rotate towards the mouse position and managed to do it with this code (look code) but I’ve got some wired rotation bugs. Also I want it to rotate slowly towards the mosue position and not instand.
You could try using body movers to orientate the turret smoothly. This would also eliminate the jittery-ness. For example, you could create a BodyGyro inside your root part in order to set the Orientation of the turret(you would want to use a high D value so that it would be smooth). Then you could create a hinge or other type of constraint to hold the Model to the tank.
I’m sure there are many other ways to do this, such as Lerp()ing or using the TweenService, but this is what I would try first.
After adding the code to the while loop the gun rotates smooth but is still rotating in the Y axis
while wait() do
workspace.T1.Turret.Gun:SetPrimaryPartCFrame(CFrame.new(workspace.T1.Turret.Gun.PrimaryPart.Position, Mouse.Hit.p) *CFrame.Angles(math.rad(0), 0, math.rad(-90)))
workspace.T1.Turret.Gun.Hud.BodyGyro.MaxTorque = Vector3.new(math.huge, 0, math.huge)
end
Going a little off topic but how can I not make it rotate instand, like @ExcessEnergy said lerping for example. But I’m gonna need to send the gun’s CFrame over events to the server so the lerp needs to be updated and overrided everytime the mouse moves ?