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.
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)
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.
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?
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 = ""
function DoMove(dir)
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
end
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)
end
else
lastState = "moving"
DoMove(dir)
end
wait(.1)
end
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)