How can I set ONLY the orientation of the character?

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 a simple script, however when the player moves their mouse and their character, It does not snap properly: https://gyazo.com/87a468375c1963718cfbb33e3160c12a

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:

3 Likes

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

1 Like

Try to use the Unit function. EX: Direction.Unit

That’s the thing, I don’t know how

1 Like

The direction value is either 1 or -1 depending on whether the player’s facing left or right. Getting the unit is not necessary

1 Like

So, this is how it should look: ``plr.Character:SetPrimaryPartCFrame(CFrame.new(HRT.Position, Direction.Unit)

It doesn’t really matter. But I guess you are right.

1 Like

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 also do
CFrame.new(character.Position) * CFrame.Angles()
for non-relative rotations

1 Like

My idea is just do this: HRP.CFrame = CFrame.new(HRP.Position, Direction)

1 Like

I’ll give it a shot, one second.

true but in this case I think relative orientation is needed

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

that seems a bit redudant. Why would set a parts position when you can just set the HRP directly

1 Like

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.

oh yah definantly use render stepped to reduce lag and jumpy changes to the cframe

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.

You may be able to edit the C0 on the RootJoint in order to simulate the effect without actually moving the character around.

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

Oh that’s true, where’s this rootjoint found? in the HRP?