Hello! I am trying to make a dashing system for my game, but I am not very knowledgeable when it comes to things like Vector3
s (and math, but a lot of people aren’t either).
(Added a red trail to help see the dashes happening better)
As you can see from the video, you can dash fine when the camera is facing one direction, but once you start moving the camera around, it looks all wrong.
The code below isn’t the full script, just cut up for better readability:
--// dash function
function dashAbility(x, z)
local vector = Vector3.new(x, 0, z) --nil
local dash = Instance.new("BodyVelocity")
dash.MaxForce = Vector3.new(1e9, 1e9, 1e9)
dash.Velocity = vector * 60
dash.Parent = char.HumanoidRootPart
wait(.25)
dash:Destroy()
wait(2.5)
canDash = true
end
--// finds the movement direction of the player and creates the Vector3 based on the camera
local movementDirection = camera.CFrame:vectorToObjectSpace(human.MoveDirection).Unit
if math.abs(movementDirection.X) > math.abs(movementDirection.Z) then
if movementDirection.X < 0 then
dashAbility(movementDirection.X, 0)
elseif movementDirection.X > 0 then
dashAbility(movementDirection.X, 0)
end
elseif math.abs(movementDirection.X) < math.abs(movementDirection.Z) then
if movementDirection.Z < 0 then
dashAbility(0, movementDirection.Z)
elseif movementDirection.Z > 0 then
dashAbility(0, movementDirection.Z)
end
else end
I believe it’s because the X and Z values are supposed to be flipped when the camera is facing different directions or something. The script seems to be working fine, the problem is that it’s sending you towards the wrong directions.
This is the method I used for calculating the movement direction, so shoutout to them.