Hi there! Basically, what I wanna do is calculate a perfect zig zag pattern movement for my projectile part from start position to end position. By the way when I say perfect I mean I want it to go left and right/right and left everytime without breaking pattern and the left right/right left path lengths to stay the same.
Examples:
Ignore the curve path!
I have tried looking on Devforum, google, and other lua scripting help websites like scripting helpers but I can’t find anything to help me.
maybe you could use math.sin(tick()*speed) and if you want it to perfectly zig zag into a specific position you could stop the loop after the magnitude between the projectile and the target position is a certain amount
or doing tick()*speed if u think tick is too slow
it often used in camera shake but can also be used in part movement, i like to use it for cframe animations
the transition between the zig zags are pretty smooth in my opinion probably depends on the speed but here is an example of a sin looped animation i made
also i might have wrote the code wrong if it doesnt work add
CFrame.LookVector*amount u want to move*math.sin(tick())
This is very cool, thank you! I will try this out on Friday and see if it works and if it does I’ll make it as the solution. I’m very grateful for your help!
if it doesnt work another method would be to create a table of segments by getting the magnitude between the target position and the origin position the dividing it so you get your desired amount of segments. then loop through it with ipairs and tween the projectile between those segments, almost like a lightning strike
The sine method is pretty reliable if you use it well.
Although, if you want a sharper or longer zigzag, you can use modified expressions of sine. One such example is tan(sin(x)).