Basically I have a Dash function that uses Cam.CFrame.lookVector to apply BodyVelocity; for my Dash mechanic to work.
It all works great, except for one issue where the player can dash straight down, into the ground, and then be flung into the air, and sometime way out of the map.
I cannot really get a recording of this, as it is not a very common issue; yet it is still one that I want to fix regardless.
That said, all that I basically want to do is limit the direction that the player can dash in.
For example:
If the player is on the ground,
then they cannot dash downward.
I believe that limiting the Y axis some how is how this would be done, but I am not sure how to do this;
which is why I am making this post.
If anyone can get me on the right track, that would be great!
I’m testing in studio, but couldn’t you take the LookVector (Which is Vector3 value) and do vector math to remove the Y axis. Something like Direction = LookVector * Vector3.new(1,0,1).
I just tested it in studio and this option isn’t as straight to the point as I thought it would be.
To see if the player was on the ground, you’d do a raycast, with the origin being the position of the player’s root part and the direction being Vector3.new(0, x, 0) where x is slightly over half of the size of the player’s model, with parameters making it so that only the map/baseplate is considered for the raycast. If the raycast returns something, then the player is on the ground. If it doesn’t then, they aren’t.
Making it so that the player doesn’t dash downward but can dash upward is a bit simpler: you would have to reconstruct the Vector3, like so
local Velocity = Vector3.new(LookVector.X, math.max(0, LookVector.Y), LookVector.Z)
What this does is make the maximum vertical velocity the dash can have 0, meaning any velocity less than that (e.g, any velocity going downward is ignored and makes the character go forward as normal).
The effect can even be reversed by changing the math.max call to a math.min call.
(I haven’t tested this, so perhaps none of this works or makes sense.)