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

How to make a part point towards it's velocity?

Hi, im trying to make a rocket launcher. I want the rockets of the rocket launcher to be affected by gravity, and so i also want the rockets to constantly point towards their own velocity when they are flying through the air, kinda like how an arrow flies.

I got a script here, and i'm not sure what's wrong with it.

tool = script.Parent
Handle = tool.Handle

launcher = tool.Launcher

tool.Equipped:connect(function(mouse)
	mouse.Button1Down:connect(function()
		local rocket = game.ServerStorage.Missile:Clone()
		rocket.CFrame = CFrame.new(launcher.CFrame.p, mouse.Hit.p)
		rocket.Velocity = rocket.CFrame.lookVector * 100
		rocket.Parent = workspace
		while true do
			rocket.Orientation = CFrame.new(rocket.Velocity).lookVector
			wait()
		end
	end)
end)

This is the bit that doesn't work:

while true do
	rocket.Orientation = CFrame.new(rocket.Velocity).lookVector
	wait()
end

This bit doesn't do what it's supposed to, it makes all the rocket continuously point towards 0, 0, -1. Can someone figure out why this is happening?

1 answer

You're doing it wrong. When using Orientation you would use Vector3, but in this case we're using CFrame. And when you use lookVector it must have CFrame in front of it because it's a property of CFrame. So the script should look like this

while Wait(0) do
	rocket.Velocity = rocket.CFrame.lookVector * 5 -- Place any number here for the desired speed you want
end

Be careful though, because you should set the velocity to a high number otherwise the rocket would fall. Though using BodyPosition, BodyVelocity etc, will be a good idea to fix any issues and make it more efficient.

1 comment

0

But this script makes the rocket go in a straight line, at that's not what i want. I want the rockets to fly like an arrow would.

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