How to calculate Offset from linear movement?

I’m trying to simulate a zig-zag effect whilst almost maintaining a linear direction - I have attached an image below representing this.

local Projectile_Speed = 150
Connection = RunService.Heartbeat:Connect(function(step)
	local StudToMove = Projectile_Speed * step
	Part.CFrame = CFrame.new(Part.CFrame.p + Part.CFrame.LookVector * StudToMove)
end)

Above is the method of movement; as you can see, it moves along a linear path at the moment, directly in-front of the projectile. This is for reference at the moment. But the final version will be within a tool, registering the Origin as the Tool’s Handle position and the EndPoint being Mouse.Hit.p

  • Black points represent the Origin, Direction and End Point.
  • Red points represent the “Zigzag” effect that will occur during motion.

One possibility is that you could implement the sin function to the projectile. You could use the Z value as the independent value and you can find the X offset of the projectile. The function looks something like this:

The equation for the function above is (4 represents the factor of the horizontal stretch of the graph.):
image

3 Likes

Thank you!
Is there any way we can discuss this? I’m new to this kind of method but very intrigued by it.