Answered by
8 years ago Edited 8 years ago
This is kind of complex so bear with me and try to follow along. What you're trying to do can be accomplished with a BodyGyro
object.
BodyGyros control the rotation of the object. If you give it a direction to look at, it will look at it. There's a CFrame constructor that helps out alot with this: CFrame.new(vector3 origin, vector3 lookat)
.
If you supply 2 vectors as arguments, it will take the first as the spot the CFrame is looking from. The second argument is used as the spot to look at.
So.. what you can do is use the Part's position as the 1st argument, the spot for the BodyGyro to look from. The second argument is where you need the part to be looking at, so it gets tricky.
You need to get a CFrame from the part's CFrame, relative to a location it would be in, if it kept going in the direction it is traveling. If you look at the literal definition of Velocity, it states it is 'the speed and movement direction of the object'. Keyword there my fellow developer: movement direction.
Multiply the part's current CFrame with a newly created CFrame. The new CFrame will consist of the part Velocity's X, Y, and Z components.
Here's the code, i'll comment so you can follow along.
01 | local part = script.Parent |
03 | local gyro = part:FindFirstChild( "BodyGyro" ) |
06 | gyro.CFrame = CFrame.new(part.CFrame.p, |
07 | (CFrame.new(part.CFrame.p) |