Alright guys quick question, if I have two velocities that I want to apply how can I make it work.
I am making a combat system and I want to apply a force when punching, to create a type of movement when punching. But I also apply another type of velocity to keep the users in the air (being not able to air walk). The apply force is destroying the velocity that keeps then in place preventing them from air walking. But the issue is that I still want to apply a force when doing air attacks to make it more realistic… how can I do that?
this is the code that keeps them in place so they dont air walk
function SpeedManager:MonitorAirCombat(character)
if not character then return end
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid then return end
local rootPart = character:FindFirstChild("HumanoidRootPart")
if not rootPart then return end
local airCombatVelocity
local function applyAirCombat()
if character:GetAttribute("AirCombat") then
if not airCombatVelocity or not airCombatVelocity.Parent then
airCombatVelocity = Instance.new("BodyVelocity")
airCombatVelocity.Name = "AirCombatVelocity"
airCombatVelocity.Velocity = Vector3.new(0, 0, 0)
airCombatVelocity.MaxForce = Vector3.new(400000, 0, 400000)
airCombatVelocity.P = 1250
airCombatVelocity.Parent = rootPart
end
else
if airCombatVelocity then
print("yup canceled")
airCombatVelocity:Destroy()
end
end
end
applyAirCombat()
character.AttributeChanged:Connect(function(attributeName)
if attributeName == "AirCombat" then
applyAirCombat()
end
end)
end
this is the code that forces them to advance a bit after each M1
local function applyForce(target, direction, magnitude)
if target.HumanoidRootPart:FindFirstChild("AirCombatVelocity") then
return
end
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Name = "TemporaryForceVelocity" -- Unique temporary name
bodyVelocity.Velocity = direction * magnitude
bodyVelocity.MaxForce = Vector3.new(5000000, 5000000, 5000000)
bodyVelocity.P = 10000
bodyVelocity.Parent = target.HumanoidRootPart
task.delay(0.2, function()
if bodyVelocity and bodyVelocity.Name == "TemporaryForceVelocity" then
bodyVelocity:Destroy()
end
end)
end
And this is how I apply the applyforce
local validAttackTypes = {["M1"] = true, ["M2"] = true, ["M3"] = true, ["M4"] = true, ["M5"] = true}
if validAttackTypes[attackType] then
applyForce(hitHumanoid.Parent, (hitHumanoid.Parent.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).unit, forceMagnitudeEnemy)
applyForce(player.Character, (player.Character.HumanoidRootPart.Position - hitHumanoid.Parent.HumanoidRootPart.Position).unit, -forceMagnitude)
end```
so as you can see I use an `if` statement so that the applyforce is only used on m1-m5 and not uplift and air attacks, but what I want is to apply the applyforce on all attacks not just the ground ones....
Hope it was clear thanks