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

How would I go on about making a part go forward forever from the direction I'm pointing it at?

I'm trying to make a projectile of sorts, a part that goes forward and explodes on contact. I want to make it go forward in the direction the origin part is pointed at, and I'm conflicted on how to do that. I think it's got something to do with lookVector, but I'm not too sure. Here's a script I was tinkering around with:

tool = script.Parent
part = tool.Handle
while true do
	wait()
	part.Position = part.CFrame.lookVector * CFrame.new(0, 0, -5).p
end

This doesn't work, obviously, because it only goes in a certain direction.

2 comments

0

What's the origin part?

0

A handle for a tool. It is a simple 1x1x1 part.

1 answer

I'd recommend using a BodyVelocity object, but if you absolutely want to do it manually with CFraming then it's as simple as this:

part.CFrame = part.CFrame * CFrame.new(0, 0, -speed)

Here I'm combining two CFrames together; the part's current CFrame and a new CFrame pointing towards negative Z, that is, forward. By combining these two CFrames, I'm effectively translating the first towards the direction described by the second, relative to itself.

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