Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago

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.

0
What's the origin part? OldPalHappy 1477 — 7y
0
A handle for a tool. It is a simple 1x1x1 part. Rodmane234 85 — 7y

1 answer

Log in to vote
0
Answered by
Link150 1355 Badge of Merit Moderation Voter
7 years ago
Edited 7 years ago

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.

Ad

Answer this question