Love the tutorial, especially showing the importance of math to doing this stuff!
One question though, if I don’t have a sphere following the path but a rod, what would be the best way to rotate it so that it is always pointing in the direction of the arc? At first I was thinking about doing a BodyAngularVelocity from 0 to pi, but that won’t work in a local script. Would I have to use CFrames then?
EDIT: Ok, here’s what I’ve got so far:
Right before the while (nt < t*2)
loop, I put this in to set the starting angle of the projectile and point it at the target.
local angle = math.pi / 4
p.CFrame = CFrame.new(p.Position, hrp.Position)
Then, inside of the while loop I have:
p.CFrame = p.CFrame * CFrame.Angles(0, angle, 0)
And after the RenderStepped update:
angle = (math.pi / 4) - ((nt / (t * 2)) * (math.pi / 2))
What this should do is start the projectile pointing at the target, then up at a 45 degree angle. Then, on each render step, it subtracts from that angle a proportion of the full rotation of the projectile. The end result is moving from a +45 angle to a -45 angle by the end of the animation.
However, when I run it, I don’t see the projectile actually rotating. I printed out all my angles as it calculates them, and they look correct, running from +.76 to -.80.
Can anyone see what I’m doing wrong?
EDIT 2: I figured out some of the mistakes I made in that code. Turns out that I can’t do the CFrame.Angles with the argument of the angle I want it pointed to, but I have to use an argument for how much I want it rotated by.
So instead of calculating the necessary angle for each step, I just have to calculate the change in angle between each frame:
local angleDelta = ((math.pi / 4) / t) / 60
Because I couldn’t see a good way to calculate the number of times the animation loop will run, I took the amount of the rotation (45 degrees) divided by the time to take that rotation (t) divided by the number of frames per second (I assumed 60 because that is the cap and I don’t know a good way to get the actual value).
Then, in the animation loop, I have:
projectile.CFrame = projectile.CFrame * CFrame.Angles(-(angleDelta), 0, 0)
Now when I have a static projectile that is not moving, it rotates the correct amount in the correct duration. But when I try to combine it with the CFrame change from projectile.CFrame = CFrame.new((.5 * g * nt * nt) + (v0 * nt) + source.Position)
, it doesn’t rotate. I also tried combining the two together with a multiplication, but that doesn’t work either.
Any ideas why I can’t get the two working together?