Hello! I am currently making a custom movement system for my game, and ive made so much progress so far.
I make this post because I’m unsure how I should make the players character turn to face the direction they are walking to. Any help would greatly be appreciated.
Well, you have to be getting a vector with the direction you are wanting to move, I know this because the character does move in the direction.
So you just make the character’s body (primary part) rotate (with an align orientation) to be facing the vector of where you are moving.
I tried this yes, but unfortunately it didnt work. Im not sure if im doing it right tho, could you show me an example?
Try this, maybe this can help. (Just know that I don’t actually have a custom character controller, so I threw this one together in the last hour or so, but maybe its enough to demonstrate how to do the rotation)
CustomCharacterMovement.rbxl (44.0 KB)
You can calculate the unit vector between last frames hrp cframe and current frame hrp cframe, based on that you can orientate the character on the direction they’re moving.
Im sorry for the late response!
How could i accomplish this?
Hello! so sorry for the late response. I looked into the code here, and i tried to impliment it into my system but it still didnt work. Im not exactly sure what method you used for this tho, could you go into detail?
so here is the script
script.Parent.PrimaryPart.Anchored = true
local custom = workspace.Custom.PrimaryPart
local alignPosition = custom.AlignPosition
local alignOrientation = custom.AlignOrientation
workspace.CurrentCamera.CameraSubject = custom
local speed = 16
local hipHeight = custom.HipHeight.Value+(custom.Size.Y/2)
alignPosition.Position = custom.CFrame.Position
alignOrientation.CFrame = custom.CFrame
local lastState = ""
alignPosition.MaxVelocity = speed
local src = Vector3.new(custom.CFrame.Position.X,hipHeight,custom.CFrame.Position.Z)
local dst = ((src + (dir*speed))*Vector3.new(1,0,1))+Vector3.new(0,hipHeight,0)
local rot = CFrame.lookAt(src,dst)-src
alignOrientation.CFrame = rot
alignPosition.Position = dst
while true do
local dir = script.Parent.Humanoid.MoveDirection
if dir.Magnitude<.5 then
if lastState ~= "idle" then
lastState = "idle"
alignPosition.Position = Vector3.new(custom.CFrame.Position.X,hipHeight,custom.CFrame.Position.Z)
lastState = "moving"
The main thing to have is a direction of which the character is moving…
Then, once you have that direction, you rotate the characters body to face that direction
The above code gets the characters position (src) and a position to where the character is trying to move (dst) then gets a cframe rotation (rot) that will be used to rotate the character
Then in my case, (using an anignOrientation) I supply it the rotation cframe
There is also another code in the place, that is server side, and it sets the NetworkOwnership of the object to the player (so the player has control from the client of the custom character)
character.PrimaryPart.Anchored = true