Hey, I’m creating a throwable grenade for my game and have run into an issue. When the player presses “E”, the grenade should be thrown in front of them. The issue is that if the player rotates their character, the grenade launches behind them or to the side. I’m not quite sure how to fix this, but believe that I may need to use something called LookVector? Or maybe I should be using LinearVelocity, VectorVelocity, etc. instead of AssemblyLinearVelocity? Again, I’m not sure, so any help is much appreciated.
LocalScript: (I will serverside the physics once I figure this out)
local UIS = game:GetService("UserInputService")
local LocalPlayer = game:GetService("Players").LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local tool = script.Parent
local character = LocalPlayer.Character
UIS.InputBegan:Connect(function(Input, IsTyping)
if IsTyping == false then
if Input.KeyCode == Enum.KeyCode.E and tool.Parent.Name ~= "Backpack" then
local grenadeClone = ReplicatedStorage:WaitForChild("GrenadeModel"):Clone()
grenadeClone.Parent = workspace
-- // The two most important lines.
grenadeClone.PrimaryPart.CFrame = character.ProjectileSpawn.CFrame -- // ProjectileSpawn is a part which is parented to the player's character when they join.
grenadeClone.PrimaryPart.AssemblyLinearVelocity = Vector3.new(0,0,-30) -- // Applies velocity to the grenade.
end
end
end)
And also, have a Remote Event for the grenade on the server and send the direction because that grenade can only be seen on the client and explode on the client which would do 0 damage to other players
In my OP, your code was the solution as I wasn’t sure how to use the mouse. However, I realize Larry’s method is much a much cleaner method of doing it. Thank you for your reply though