Slope alignment/ character turning for sonic engine

so I’m here today on the dev fourms to post about problem with making my game engine for sonic shards
when I coded the turning for sonic he does not turn and I don’t know why and I need it fixed

robloxapp-20221113-1519236.wmv (2.5 MB)

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

--  this is the code
local hum = script.Parent:WaitForChild("Humanoid")
local HumanoidRootPart = script.Parent.HumanoidRootPart

player = game:GetService("Players").LocalPlayer.Character

_G.moving = false

hum.AutoRotate = false
-- rotation
rootpos2 = HumanoidRootPart.CFrame.Position


local ray = workspace:Raycast(rootpos2, Vector3.new(0,10,0))	
while game:GetService("RunService").Heartbeat:Wait() do

	
	


	local moveDir = hum.MoveDirection


	if  moveDir.Magnitude > 0.1 and  ray  then
		local upvec = ray.Normal.X
		local rootPos = HumanoidRootPart.CFrame.p
		HumanoidRootPart.CFrame =  CFrame.new(upvec, rootPos.Y + moveDir.Y, rootPos.X) 
	
	
	
	end
end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Your “upvec” is not a vector, but a single number, is that what you intended?
CFrame.new(x,y,z) creates a CFrame at the given xyz position with Identity (default) rotation, so your character will never be rotated.

Based on how this has been pieced together, I assume you want your character to both rotate towards the direction of movement, and to rotate up and down when walking on slopes? Is that correct?

Where are you trying to rotate the player?
All of the information in your script is about the Position of the Humanoid, not the Orientation.

you are correct about what I’m trying to do the upvec is supposed to be the X axis of the normal of what the character is standing on and I’m trying to add the hrp CFrame.P with the move Direction but with it’s Y axis for the y axis of the new CFrame.P, have the upvec be the X axis of the new CFrame.P and have the and have the Z axis of the hrp CFrame.P be the Z axis of the new CFrame to make the character do that but it does not seem to be working

While the character is moving you can obtain this effect by setting their rotation to be based on their velocity:

local characterCf = CFrame:LookAt(Vector3.zero, characterVelocity, Vector3.yAxis)

If the character is stopped, you should make them stand straight up facing whatever direction they were before they came to a stop.

like this
local hum = script.Parent:WaitForChild(“Humanoid”)
local HumanoidRootPart = script.Parent.HumanoidRootPart

player = game:GetService(“Players”).LocalPlayer.Character

_G.moving = false

hum.AutoRotate = false
– rotation
rootpos2 = HumanoidRootPart.CFrame.Position

local ray = workspace:Raycast(rootpos2, Vector3.new(0,10,0))
while game:GetService(“RunService”).Heartbeat:Wait() do

local moveDir = hum.MoveDirection


if  moveDir.Magnitude > 0.1 and  ray  then
	local upvec = ray.Normal.X
	local rootPos = HumanoidRootPart.CFrame.p
	HumanoidRootPart.CFrame = CFrame:LookAt(Vector3.zero, _G.foward , Vector3.yAxis)



end

end

_G.foward is how the speed is handeld it is the number that multiplies the CFrame of the Humaniod RootPart to make it move

Yes but you probably should not store it under _G, do you need to share this information with other scripts? If not just make it a local variable. Using _G opens you up to a lot of possible errors if you use it to communicate between scripts.

Ok and yeah now that I think about it do I need to use _G for this? I probably should not givin the fact that I’m going to put all the code for the engine in one script or two so yeah I think that I’m going to get rid of _G cause some times when I used it, it did cause a lot of problems now with that out of the way I’m going to go test this out now

image

for some odd reason this does not work can you maybe help me on why this does not work for me

Why do you call it “playersh*t” exactly?