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

character tilt system not working properly, a little help?

Asked by
Jirozu 71
3 years ago
Edited 3 years ago

i was working on making a tilt system for the player that tilted them in the direction they were turning in, like this gif:

https://gyazo.com/e599a9630dbb759e85ee3b6b3442bc40

but I ran into a problem, the character doesn't tilt or show any signs of tilting at all. I was trying to make the tilt a little bit noticeable, but not too heavy as I personally don't like tilt systems like that. Here is the code I have below.

local dir, vel
local origin = root.RootJoint.C0
local angle = 0
local roll = 0
local function character_tilt()
    local function lerp(a, b, t)
        return a + (b - a) * t
    end

    vel = root.Velocity * Vector3.new(1, 0, 1)
    if vel.Magnitude > 2 and vel.Magnitude < 15 then
        dir = vel.Unit
        angle = root.CFrame.RightVector:Dot(dir)/2
    else
        angle = 0
    end
    print(angle)
    local results = lerp(roll, angle, 0.1)
    root.RootJoint.Transform = root.RootJoint.Transform * CFrame.Angles(0, roll, 0)
end

1 answer

Log in to vote
0
Answered by
Jirozu 71
3 years ago

Figured it out a couple days ago.

Changed:

root.RootJoint.Transform = root.RootJoint.Transform * CFrame.Angles(0, roll, 0)

Into This:

root.RootJoint.C0 = origin * CFrame.Angles(0, -results, 0)

and that fixed my problem.

Ad

Answer this question