I have a script that throws the block to where the character is facing, but the problem is that the projectile does not shoot and it falls, I want it so that it shoots from humanrootpart and fire straight defying gravity at where the player is facing…what I have so far:
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local camera = workspace.CurrentCamera
local Player = Players.LocalPlayer
local pathToThePart = ReplicatedStorage.Part
UIS.InputBegan:Connect(function(Key, Chatted)
if Chatted then
return
end
if Key.KeyCode == Enum.KeyCode.E then
local projectile = pathToThePart
projectile.Parent = workspace
projectile.CFrame = Player.Character.HumanoidRootPart.CFrame
projectile.Velocity = camera.CFrame.LookVector * 100
end
end)
another question…my game is 2d so the look victor is facing the background…how do i change it so that it fires at where the player 's humanrootpart(other bodypart) is facing?
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local camera = workspace.CurrentCamera
local Player = Players.LocalPlayer
local pathToThePart = ReplicatedStorage.Part
UIS.InputBegan:Connect(function(Key, Chatted)
if Chatted then
return
end
if Key.KeyCode == Enum.KeyCode.E then
local projectile = pathToThePart
projectile.Parent = workspace
projectile.CFrame = Player.Character.HumanoidRootPart.CFrame
projectile.Velocity = Player.Character.HumanoidRootPart.CFrame
end)
Hmm not quite. The way to use body velocities is actually the most easiest to do.
Create a BodyVelocity in the part you want to move.
Set the BodyVelocity.MaxForce to math.huge or ‘inf’
Set the BodyVelocity.Velocity to the direction * speed
CFrame.lookVector is a direction.
Because of this you can not directly assign it unless you use CFrame.fromMatrix() which I highly recommend you don’t use until you fully understand CFrame
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local camera = workspace.CurrentCamera
local Player = Players.LocalPlayer
local pathToThePart = ReplicatedStorage.Part
UIS.InputBegan:Connect(function(Key, Chatted)
if Chatted then
return
end
if Key.KeyCode == Enum.KeyCode.E then
local projectile = pathToThePart
projectile.Parent = workspace
projectile.CFrame = Player.Character.HumanoidRootPart.CFrame
projectile.BodyVelocity = Player.Character.HumanoidRootPart.CFrame.lookVector * 1000
end
end)
and the projectile dosn’t fire… it just stay where my charcter is…