How would I code the trajectory of an object?

I’ve already attempted this, but the code, for one, sends the projectile through an arc ending at the mouse’s hit point, and two, due to me using lerp as I don’t know how else I would move the rock, it slows down greatly before hitting the end point.
How could I make the rock follow the angle of fire and move at a constant speed?
Code:

while 5==5 do
		pChar=player.Character
	
		local P1=pChar.HumanoidRootPart.Position
		local sH=(mhit-P1).Magnitude
		local sO=mhit.Y-P1.Y
		local theta=math.asin(sO/sH)
		ex=( Vector2.new(rock.Position.X,rock.Position.Z) - Vector2.new(mhit.X,mhit.Z) ).Magnitude
		local rockheight=(ex+math.tan(theta)-
			((workspace.Gravity*ex^2) / ( 2*(Velocity^2)*( math.cos(theta)*math.cos(theta) )) )
		)
		desiredpos=Vector3.new(mhit.X,rockheight,mhit.Z)
		
		rock.CFrame=rock.CFrame:Lerp(CFrame.new(desiredpos),.1)
		
		print("(",P1,")",theta,ex,rockheight,"	(",rock.Position,")")
		task.wait()
	end

Incase there’s any confusion, this is encased in a function with “player:Player, mhit:Vector3, rock:Instance” in the parenthesis.

1 Like

You could tween it instead, and pass down a TweenInfo that uses a constant easingStyle.
Though, tweening CFrames on the server, especially if done with multiple instances, can be quite performance heavy. I’d recommend you run this logic on the client.

I highly recommend this article: Modeling a projectile's motion

What you’re doing is pretty over-complicated and inefficient.

What would I tween though? Like would I make a table of points along the trajectory and tween to each one? and if i did how would i get the points?

Essentially yes, but that would probably end up looking mechanical and isn’t the most performant.
If what you are looking for is a projectile for combat or something that requires a more natural feel, you should adapt the method suggested by @doomguy2164, or you could try using a Vector3Curve.