Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how do i make my projectile launch?

Tear = game.ReplicatedStorage.tear
local plr = game.Players.LocalPlayer

UserInput = game:GetService("UserInputService")

UserInput.InputBegan:Connect(function(input , gameProccesedevent)
	if input.KeyCode == Enum.KeyCode.E then
		local tearclone = Tear:Clone()
		tearclone.Parent = game.Workspace
		tearclone.CFrame = plr.Character.HumanoidRootPart.CFrame + plr.Character.Head.CFrame.lookVector * 5
	end
	
end)

this is the script. now it just spawns balls in front of my head. i also have a head turning script so it spawns where i look. now i need to launch the projectile. i don't want it to fly like an anchored object moving in a straight line. i want it to launch like an unanchored object launched and has gravity. thanks.

1 answer

✓ Accepted answer

Use the AssemblyLinearVelocity property.

local Tear = game.ReplicatedStorage:WaitForChild("tear")
local plr = game.Players.LocalPlayer

local UserInputService = game:GetService("UserInputService")

local speed = 5 -- YOU CAN CHANGE THIS

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if not gameProcessedEvent then -- if player is not typing
		if input.KeyCode == Enum.KeyCode.E then
			local char = plr.Character
	if not char or not char.Parent then -- if player's character hasn't loaded
		char = plr.CharacterAdded:Wait()
	end
			
			local tearclone = Tear:Clone()
			tearclone.Parent = workspace
			
			tearclone.CanCollide = true
			tearclone.Anchored = false
			tearclone.CFrame = char.Head.CFrame + char.Head.CFrame.LookVector
			
			tearclone.AssemblyLinearVelocity = tearclone.CFrame.LookVector * speed
		end
	end
end)

6 comments

0

the projectile isn't launched, it spawns inside of the player's torso pushing him backwards a little, and the projectile slides across the floor. i don't know how to make it launch

0

wdym by "launch"?

0

There I edited the script.

0

i mean like it was shot out of something. like if you picked up something in your hand and throw it, then it falls down

0

I figured out why it didn't work. I forgot to add "CFrame" between "tearclone" and "LookVector" in line 23. I edited the script and it should work now.

0

oh my god Thank you!!!!

This discussion is preserved as it was. New answers, comments, and votes are closed.