Make a part face its velocty/ the direction its going

Now, i have looked at multiple posts and still havnt found a solution. I have a shell of a naval gun
Its fired with a body velocity and takes a desired path and work swith the gun nicely, however it keeps the same rotation and im finding this rather annoying

As you can see its slightly upwards and stays this way throughout its path.

any way to change that?

image

1 Like

You can either use another bodymover or set the rotation through the object’s cframe every frame like so.

part.CFrame = CFrame.LookAt(part.CFrame, part.CFrame + part.Velocity.Unit)

There might be a slightly more performant way to write this, but this should work.

I attempted this owever i got the error
image

Cant exactly figure out whats nil here.

mb, there were a few mistakes with what I wrote. (the L in lookat shouldnt be capitalized and the arguments should be vectors3)

part.CFrame = CFrame.lookAt(part.Position, part.Position + Part.Velocity.Unit)

Try this instead

Yeah idk why i didnt notice that

Doing this just seems to send the script to about 7 trillion studs in the y axis

So you have the velocity, I assume, which is the direction.

part.CFrame = CFrame.lookAt(part.Position,part.Position+velocity)
2 Likes

Try adding a bodygyro or an alignorientation and setting the cframe of that instead, if you use an alignorientation make sure rigidityenabled is true.

Either that or try updating the cframe on renderstepped or some other post-physics simulation.