How to change walkspeed if walking sideways

Hello All! I am having trouble figuring out how I change walkspeed of the player if they are walking side ways.

What I am trying to achieve: Depending on the way the player walks if they walk sideways I want them to walk faster than forward and backward. Im trying to use this for a weapon system that is 3rd person and the player faces realitive to the mouse.

I have searched for topics on the DevForum with the same problem and haven’t found any.

Any help is appreciated!

2 Likes

you can get the move direction first

local movedir = HumanoidRootPart.CFrame:VectorToObjectSpace(Humanoid.MoveDirection)

then set the walk speed depending on the movedir.X/movedir.Z values
So I think you can do

local x = movedir.X
if x < 0 then
x = -x
end

local y = movedir.Y
if y < 0 then
y = -y
end

^ only get no negative values for this v

local walkspeed = SpeedStraight * y + SpeedSide * x

this should work. if not then sorry its 3am rn my brain doesnt work lol

2 Likes

It somewhat works. I can move sideways but not forward

Fixed it. Instead of putting Z you put Y. Y is up down Z is forward backward. Thanks though!

1 Like

oops sorry my dude, glad it worked