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

How do I make a part move towards its Front Face?

Asked by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

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

Log in to vote
0
Answered by
MrNicNac 855 Moderation Voter
10 years ago

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)
0
Dang, I should have figured that out myself. Thanks for the help! Perci1 4988 — 10y
Ad

Answer this question