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.
Intencidy
(smelvin)
January 21, 2023, 2:59am
#2
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.
Intencidy
(smelvin)
January 21, 2023, 3:51am
#4
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?
Internally the Humanoid only sets the Y component of MoveDirection when in the swimming state, it’s not used for jumping at all, jumping is specially-cased and separate from the normal walk/run/swim movement vector, that’s why you don’t see it changing. If you swim up and down, you should see it have a value, IIRC. Maybe not. I can’t remember if this is reflected in what is exposed to Lua.
Intencidy
(smelvin)
January 21, 2023, 3:56am
#6
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.
system
(system)
Closed
February 4, 2023, 6:23pm
#9
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.