I’m trying to achieve knockback similar to arsenal where if you shoot a rocket you get knock back and go flying in the air. I have got it working but I don’t think my method is the best:
local script inside character
local players = game:GetService("Players")
local char = script.Parent
local player = players.LocalPlayer
local mouse = player:GetMouse()
local humRp = char.HumanoidRootPart
local db = tick()
local force = 100
local function create(pos,lookAt)
local part = Instance.new("Part")
part.Parent = workspace
part.Size = Vector3.new(1,1,1)
part.CFrame = CFrame.lookAt(pos,lookAt)
part.Anchored = true
part.CanCollide = false
part.Transparency = 1
return part
end
local function mouseClick()
if tick()-db < .2 then return else db = tick() end
local mousePos = mouse.Hit.Position
local distance = (mousePos-humRp.Position).Magnitude
local part = create(mousePos,humRp.Position)
humRp.Velocity = part.CFrame.LookVector*force
part:Destroy()
end
mouse.Button1Down:Connect(mouseClick)
I’m basically creating a part at the mouse, making it look at the player and using that lookVector to add knockback.
Any better methods of doing this is greatly appreciated!