Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Character rotates on a slope? (based on momentum)

Asked by 3 years ago

What I want to achieve:

I currently am making a Sonic the Hedgehog game. Everything is going well, except I have a problem. I'm trying to make slope physics that are based on your momentum, that when you reach a certain WalkSpeed, you will be able to go through loops, and take a slope up to a wall. while if you only have a minimal speed, you can't be able to go up a loop, same goes when you are halfway through a loop or when you are up a wall, when you are at a very minimal speed halfway through the loop, or when you're up a wall, you fall.

What I want to achieve (simplified form):

I want the character to rotate to the slope, except you are able to run up walls and run up loops at maximal speed. while at minimal speed, you can't. (Something like Sonic Onset Adventure or Sonic Eclipse Online)

What I tried:

I tried using rays, but that won't work, as it doesn't alternate physics at all. All it does is rotate your character, It does not allow you to run up walls at high speed, neither it lets you go through loops.

Code used (Found it in the developer forums):

local char = game:GetService("Players").LocalPlayer.Character or game:GetService("Players").LocalPlayer.CharacterAdded:Wait()
local lowerTorso, rootPart = char:WaitForChild("LowerTorso"), char:WaitForChild("HumanoidRootPart")

local params = RaycastParams.new()
params.FilterDescendantsInstances = {char}
params.FilterType = Enum.RaycastFilterType.Blacklist

game:GetService("RunService").Heartbeat:Connect(function()
    local ray = workspace:Raycast(rootPart.Position, Vector3.new(0, -char.Humanoid.HipHeight - 2, 0), params)
    if ray then
        local vector = rootPart.CFrame:VectorToObjectSpace(ray.Normal)
        lowerTorso.Root.C0 = CFrame.new(0,-1,0,1,0,0,0,1,0,0,0,1) * CFrame.Angles(vector.z, 0, -vector.x)
    end
end)

I also tried using EgoMoose's gravity controller, but It is not what I'm looking for.

You wouldn't need a slope to run up walls, it's like something with Spider-Man, not Sonic ;-; I also stated a few lines back, I want the character to go up walls and go through loops only at HIGH speed. I DID use it once, and I thought "What if I make a script that lets it disable the gravity controller at lower WalkSpeeds, and enables it once you reach top speed?"

Long story short, It did not work. again, you wouldn't need a slope or ramp to run up walls, it's just like Spider-Man, which is not what I want to achieve.

So.... any suggestions? (please provide a sample code, because I'm not a great scripter at all. I would like to study the code, so If I have another situation like this, I would fix it without asking and waiting for help.

Answer this question