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 a part move towards its Front Face?

I have used lookVector before, mostly with guns. For example,

--stuff above
bullet.CFrame = CFrame.new(tool.Handle.CFrame.p ,mouse.Hit.p)
bullet.Velocity = bullet.CFrame.lookVector * speed
--stuff below

I have also made sliding doors before. It's pretty easy to do with a for loop and CFrame.

for i = 1,20 do
	door1.CFrame = door1.CFrame * CFrame.new(0.5,0,0)
	door2.CFrame = door2.CFrame * CFrame.new(-0.5,0,0)
	wait(0.5)
end

However, I do not know how to combine these things. I'm trying to make a model which lets users place two doors on any coordinate plane they want, and the doors will still move towards each other. This is not possible with the method I used before, because it either moves the doors on a x or z plane. I want to know how to make the doors move towards their lookVector, without worrying about what coordinate plane they are on.

1 answer

✓ Accepted answer

The direction a part is facing (via the FrontSurface) will always be lookVector as you know. So, given that lookVector is only a direction, you need to use the part's position and rotation (its CFrame) and "push" it in the direction of lookVector.

Door.CFrame = Door.CFrame + (Door.CFrame.lookVector)

1 comment

0

Dang, I should have figured that out myself. Thanks for the help!

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