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

How can I use lookvector to make an object appear in front of something?

I'm making a rocket launcher and I want the rocket that the tool makes to be in FRONT of the launcher instead of in it. Because if the part is made inside of the launcher, they touch eachother and it explodes instantly.

local debounce = false

script.Parent.Activated:Connect(function()
	if debounce == false then
		debounce = true
		local char = script.Parent.Parent
		local rocket = Instance.new("Part")
		rocket.CFrame = script.Parent.Handle.CFrame --< Makes it inside of it instead of in the front
		rocket.Parent = workspace
		local BV = Instance.new("BodyVelocity")
		BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		BV.Velocity = char.HumanoidRootPart.CFrame.lookVector*50
		BV.Parent = rocket
		local exploscript = script.Parent.ExploScript:Clone()
		exploscript.Parent = rocket
		exploscript.Disabled = false
		wait(1)
		debounce = false
	end
end)

1 comment

0

currentCF = currentCF * CFrame.new(0, 0, -studsInfront)

1 answer

You would use toWorldSpace to do this.

Edit: Sorry, my old code wouldn’t work as I didn’t read the article I got it from right.

local debounce = false


local pos = CFrame.new(PUTROCKETPARTHERE.Position) * CFrame.new(0,0,-5)— fixed
local pos2 = PUTROCKETPARTHERE.CFrame:toWorldSpace(pos)

script.Parent.Activated:Connect(function()
    if debounce == false then
        debounce = true
        local char = script.Parent.Parent
        local rocket = Instance.new("Part")
        rocket.CFrame = pos2
        rocket.Parent = workspace
        local BV = Instance.new("BodyVelocity")
        BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
        BV.Velocity = char.HumanoidRootPart.CFrame.lookVector*50
        BV.Parent = rocket
        local exploscript = script.Parent.ExploScript:Clone()
        exploscript.Parent = rocket
        exploscript.Disabled = false
        wait(1)
        debounce = false
    end
end)

I think this would work, I’m not really sure. If this doesn’t work, look on the wiki about toWorldSpace.

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