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
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?
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
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
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