Hey there and merry christmas! Currently working on my 2.5D platformer Overdrive! and my dash seems to be interferring with the ground and is effecting the velocity, I’d like the dash to always do the same amount as power, wether you are in the air or on the ground, but it seems as the ground interferes with that.
I’m more of looking for something like in Verdant Moon
If you could help me with finding a solution it would be appreciated. Cheers!
Heres my current dash script.
--services
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
--player vars
local client = Players.LocalPlayer
local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local animation = script:WaitForChild("Animation")
local animator:Animator = hum:WaitForChild("Animator")
local animTrack = animator:LoadAnimation(animation)
animTrack.Priority = Enum.AnimationPriority.Action
animTrack.Looped = false
local hasLanded = true
local boosted = false
--vars
local upwardsForce = 0 --as percent of sidewards force
local boostMagnitude = 1850
local debounce = tick()
local debounceTime = .5
local boostKey = Enum.KeyCode.Q
local hotkeys = {
["W"] = Vector3.new(0,.50,0),
["A"] = Vector3.new(-1,0,0),
["S"] = Vector3.new(0,-1,0),
["D"] = Vector3.new(1,0,0),
}
--the function to get a normalized vector3 of the boost direction
local function getUnitDirection(): Vector3
--set up the return var
local resultVec3 = Vector3.zero
local isSideways = false
local isUp = false
local issidewaysup = false
for _, input: InputObject in pairs(UserInputService:GetKeysPressed()) do
if hotkeys[input.KeyCode.Name] then
--add up the vector forces based on the pressed hotkeys (W/A/S/D)
resultVec3 += hotkeys[input.KeyCode.Name]
end
if (input.KeyCode == Enum.KeyCode.A or input.KeyCode == Enum.KeyCode.D and (not isSideways) and input.KeyCode ~= Enum.KeyCode.W) then
isSideways = true
end
if input.KeyCode.Name == "W" then
isUp = true
end
end
if resultVec3.Magnitude > 0 then
--return the normalized vector
return resultVec3.Unit, isUp, isSideways, issidewaysup
else
--return (0,0,0) if no direction vector can be normalized
return Vector3.zero, isUp, isSideways, issidewaysup
end
end
local function boost()
--apply the boost force
local direction, isUp, isSideways, issidewaysup = getUnitDirection()
local boostVector = Vector3.zero
game:GetService'RunService'.Heartbeat:Wait()
if isUp then
boostVector = getUnitDirection() * boostMagnitude * .5
elseif isSideways then
boostVector += Vector3.FromAxis(Enum.Axis.Top) * upwardsForce * boostMagnitude + getUnitDirection() * boostMagnitude * 0.6
end
char.PrimaryPart:ApplyImpulse(boostVector)
--update the vars
boosted = true
hasLanded = false
--play the animation
animTrack:Play()
end
UserInputService.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean)
--ignore input on UIs, chat, etc.
if gameProcessedEvent then return end
--only boost if the designated hotkey was used
if input.KeyCode == boostKey and tick() - debounce > debounceTime and not boosted then
boost()
end
end)
while wait() do
if not hasLanded then
local rayOrigin = char.HumanoidRootPart.Position
local rayDirection = Vector3.new(0, -3, 0)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {script.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.IgnoreWater = true
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult then
animTrack:Stop()
hasLanded = true
boosted = false
debounce = tick()
end
end
end