I’m currently attempting to make a direction snap mechanic, making the player snap to face the direction of the mouse. A bit like terraria (except it works when you move).
It’s a very simple script, I’ve handled it in a localscript, as I knew it would replicate across all other clients. However, when i did that, The character rotated a tad bit before snapping on other player’s screens. So I ended up switching to handling it on the server, by connecting it with a remotevent.
FlipEvent.OnServerEvent:Connect(function(plr,Direction)
local HRT = plr.Character.HumanoidRootPart
local Direction = HRT.Position + Vector3.new(Direction,0,0)
plr.Character:SetPrimaryPartCFrame(CFrame.new(HRT.Position, Direction))
end)
It’s also worth mentioning, I’m using BodyVelocity to move the player, as the default roblox movement module makes the player turn toward their destination.
Here’s a screenshot of the micro profiler if that helps identify the problem:
now this is a guess but you could consider using cframe.angles to change the HRP rotation so it doesnt effect the current cframe position at all. This is just a first guess though so it might not work
oh its simple. To change a parts cframe rotation just do part.CFrame = part.CFrame * CFrame.Angles(math.rad(90), math.rad(90), math.rad(90)). This would rotate the part to 90 degrees on each axix. It is very important to use math.rad as it converts the degrees to radions so the cframe can be changed by inputting degress instead of having to do the math to get the radians.
You could make a new part, make it invisible, and set can collide to false, keep anchored to true and set the cframe to the frame of the hmr, then set the orientation of the character to the orientation of the part
Still snappy, It’s not a problem with the cframe math, it just does not update at the same render cycle, I’ll try binding it to render step and i’ll see what happens.
A second option is to actually using tweening and tween the players HRP to the mouse’s direction so it is smooth and doesnt mess up the camera by snapping.
Tweening’s a bad idea, I’m trying to instantly update the CFrame, the snappiness occurs because the position and cframe dont match up. I’ve tried to bind it to renderstep via an anonymous function however, that doesn’t work