Hello! I recently picked up an idea for a game and while working on it I encountered a problem that I can’t seem to solve which is the dashing directions when a player wants to dash towards a certain direction. For better understanding here’s an example of what I mean:
What I’m trying to achieve:
What I’m stuck with:
I’m not sure how the game in the working video manages to dash towards the direction the player actually intends dashing towards. Any idea or sample code would be appreciated
Easiest way to do this is to just get the move direction of the player, remove the y value by multiplying by Vector3.new(1,0,1) and getting the unit of the direction. Then you have the direction of your dash. If you detect that the magnitude of the movedirection is under 0.5 or something (normally around 1 if you’re moving but do this just in case) then dash with the root part look vector.
Edit: note this does allow for diagonal dashing though.
Apply the force on the player as a world position, and use Camera.CFrame:VectorToWorldSpace(normalizedVelocity) to get a normalized velocity vector relative to the camera’s angle, then multiply it by the force of the velocity and you got yourself what you’re looking for.
You can get a normalized vector by using this function:
local function NormalizeVector(vector: Vector3 | Vector3int16 | Vector2 | Vector2int16)
return if (vector.Magnitude == 0) then vector else vector.Unit
end
I’m entirely sure how diagonal dashing would look but the general idea would be do only allow dashing in the green directions with by pressing the dash button while running with W,A,S or D like this:
This sounds like the kind of solution I’m looking for but I’m having trouble understanding what it means to “Apply the force on the player as a world position”
If I understand correctly you could use uis or contrxtactionservice like how @SilentSuprion said. You would probably just bind the dashes to the wasd keys. I’m kinda confused as to what the difference between the first and second videos are.
The only major difference in the second video is that once you disable shiftlock the character dashes towards its character’s right not towards the camera’s right
Ohhhh the second half of the video did not load for me . Yea move direction would be a good way to go, just you might want to filter out diagonal values. Or, you could have it use the camera cframe’s lookvector and right vectors to get the directions, though their y value has to be filtered.
Don’t use BodyGyros or anything in-between, use AssemblyLinearVelocity, more particularly :ApplyInpulse.
Use the ApplyInpulse function on the RootPart of the character.
Note: If you do use ApplyInpulse, make sure to multiply your velocity with the result of Character:GetMass, otherwise you will end up with an inconsistent velocity per character.
Do note that the velocity drops off unlike bodyvelocity, so you’ll have to compensate for that by continuously applying the force.
Edit: by velocity I mean assemblylinearvelocity
What I meant is it slows down over time, so if he wants the dash to have a constant force throughout the length of the dash he has to continuously set it.
Yea I was just adding it just in case.
Edit: also just in case you encounter this issue, I believe you tend to dash more mid air because theres no friction, so you can try to account for this by applying less force in the air.
Man there’s so much to velocity I thought I was on the safe side having spent 2 months in ROBLOX studio. Thanks to you both of you for the suggestions I’ll look up the stuff you both have mentioned and see the results
Friction is not accounted for by using this, simply because friction on Humanoids do not lower the velocity output by much, so you are allowed to get away with not including it.
Using your logic, you would have to increase the velocity when the player is on the ground, not in the air.
??? From my experience launching the player mid air throws them very far compared to just throwing them on the ground. My logic means that you have to apply less force in the air, not more. I’m saying that the friction diminishes the applied force when you’re standing.
Using ApplyInpulse is far different than setting a fixed value for AssemblyLinearVelocity. From my experiences, I’ve never encountered what you’ve stated.