How do I ignore y-axis in Humanoid.MoveDirection

Hello, I’m creating a swim script, it’s perfect, but I want it so you can’t swim down, you can only swim left and right. How would I accomplish this? So far I tried doing something like this…

velocity = (humanoid.MoveDirection * Vector3.new(1, 0, 1)) * humanoid.WalkSpeed

but, it doesn’t work. If you need more info just reply. Any ideas are appreciated.

Thank you.

You can try creating a new Vector3 object with its Y-axis set to 0, and X and Z axes being set to the move direction’s.

local direction = Vector3.new(humanoid.MoveDirection.X, 0, humanoid.MoveDirection.Z)
velocity = direction * humanoid.WalkSpeed
1 Like

Seems like a smart idea, yet it doesn’t work sadly. Here’s what I did:

swim.Velocity = Vector3.new(humanoid.MoveDirection.X, 0, humanoid.MoveDirection.Z) * humanoid.WalkSpeed

It’s weird.

Are there any errors in the output?

No, I believe it’s just the way move direction works. Is there a work around move direction or an alternative?

Well, you could add a Vector Force inside the character’s HumanoidRootPart and change its force with the formula.

1 Like

Okay good news! It works, but since it’s a vector force I keep sinking even if I increase the velocity.

Okay so I figured out the problem was because I was using body velocity. After switching to linear velocity it worked. Thank you for your time and support.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.