Im trying to make simple fighting script where the victim is pushed by the velocity in the Look Direction of the puncher but i dont have any idea how to combine LookDirection and Velocity togheter that’s why im asking for help
LookVector is a vector and so is Velocity. That’s all I have to say.
The only difference is LookVector is a unit vector while velocity is not. But, you can make it into a unit vector like so:
Velocity.Unit
This is true but it sounds like it’s a multiplicative effect thing. They want to move the target in the direction of their LookVector, but with a multiplier which would be the velocity of the punch.
You can grab the LookVector of the hitter by using CFrame.LookVector (and I think you can go from the puncher to their CFrame by something like:
Character.PrimaryPart.CFrame.LookVector)
And then you’d just multiply it by that Velocity.
So something like:
local Puncher = -- Character
local Velocity = Vector3.new(1, 1, 1) -- some velocity amount
local force = Puncher.PrimaryPart.CFrame.LookVector * Velocity
There’s also some punch tools from way back when that did this same thing, so you should be able to find those in the Free Models if you look for them. You can take a look in the code for that, and it would probably be something similar.
If that’s so then you need to use .Magnitude
with the velocity.
local Attacker = -- Character
local force = Attacker.HumanoidRootPart.CFrame.LookVector * Attacker .HumanoidRootPart.AssemblyLinearVelocity.Magnitude
Just want to add that because Unit Vectors range in values between 0 and 1 you will need to have a sizeable Vector3 to add for the lookVector.
I was messing around with Studio and usually you need a value of over 15 to make any meaningful movement. I will add my code below for reference since I tested it, however it follows the same principles as @L2000 laid out. Would not recommend using this code, it was thrown together to get a proof of concept out.
local proximityprompt = script.Parent
local rig = script.Parent.Parent.Parent
proximityprompt.Triggered:Connect(function(playerTriggered)
local character = playerTriggered.Character
local lookVector = character.PrimaryPart.CFrame.LookVector
rig:FindFirstChild("HumanoidRootPart").Velocity = Vector3.new(150,150,150) * lookVector
end)
I dont know if there’s something that im missunderstanding but nothing here seems to work for me
here is my (server) script if you see an error with the velocity somewhere (Line 28):
Event1.OnServerEvent:Connect(function(plr)
local HRP = plr.Character:FindFirstChild("HumanoidRootPart")
local Char = plr.Character
print(HRP.CFrame.LookVector)
local Hitbox = Instance.new("Part", game.Workspace)
Hitbox.Size = Vector3.new(3.9, 5.1, 2.35)
Hitbox.CFrame = HRP.CFrame * CFrame.new(0, 0, -2.5)
Hitbox.CanCollide = false
local Weld = Instance.new("WeldConstraint", game.Workspace)
Weld.Part1 = Hitbox
Weld.Part0 = HRP
Hitbox.Touched:Connect(function(Victim)
if Victim.Parent:FindFirstChild("Humanoid") then
if Victim.Parent.Name ~= plr.Name then
if debounce == false then
debounce = true
local VictimHRP = Victim.Parent:FindFirstChild("HumanoidRootPart")
local VictimHUM = Victim.Parent:FindFirstChild("Humanoid")
local Attacker = Char
local force = Attacker.HumanoidRootPart.CFrame.LookVector * Attacker.HumanoidRootPart.AssemblyLinearVelocity.Magnitude
VictimHUM.Health = VictimHUM.Health - 0.5
Hitbox:Destroy()
VictimHUM.WalkSpeed = 5
wait(0.2)
VictimHUM.WalkSpeed = 17
debounce = false
end
end
end
end)
wait(0.1)
Hitbox:Destroy()
end)
Just assigning the velocity itself isn’t going to work well, I recommend using a mover like LineForce
(to pull the player away) or use AlignPosition
(to move to the player to a place away) or even a VectorForce
(apply a force in the direction away from attacker)
Im sorry i dont understand how could i do that except by creating a velocity with an instance but i have no idea what to do next