Simplest, Performant, Linear Projectile Methods? (part to projectile to part)

This is my first post, please instruct me if anything is missing.

Essentially all I want to know is the most performant way of handling a linear projectile. Basically partA launches projectile at partB, think like a tower defense game. So projectiles would also be fired rapidly from multiple different parts. I’ve heard TweenService isn’t good but I never could grasp why. Would that be the most efficient way in this case? I’m not very knowledgeable with different projectile methods, and everything I’ve tried doesn’t seem like the most efficient way. I feel like it’s a simple question with a simple solution, I hope lol.

1 Like

I don’t know about why using TS is bad, but in the past for a rocket system I used Bezier Curves (and a module that allowed for more than 4 parts because i wanted the rocket to fly randomly before hitting the target) and just constantly updated the target position so if the time scale isnt too large and the target moved, the rocket would still hit them.

I thought Bezier Curves were used for the trajectory a projectile would fly so I’m afraid I don’t even understand how that would be used for a rocket, let alone rapid firing projectiles directed at a target via code. This may reveal how clueless I am with some concepts though

The main idea behind bezier curves is specifying t (a percentage 0 to 1) and the function will return a position that is at t%, so if you just do for t = 0,1,.05 do print(bezfunc(t)) wait() end you would get a smooth transitioning position which you can attribute to a part, you can also specify a 2nd point and drag it up a little and the line will become distorted upwards

It took me a while but I think I understand. When a target is moving, which they will be, the bezier curves ensure the projectile hits the target right? If that’s the case then I’ll have to add that at some point and I definitely appreciate that info!

Now pretend the part and target aren’t moving and the projectile is taking a linear path from one point to another. What I don’t understand is the most performant way of launching a projectile like that. I was thinking of using BodyMovers but constraints seem to be preferred. I don’t know, I’ve got some ideas to try now I’ll post what I deem to be the most performant solution if I find it.

Bezier Curves support multiple points, so just have 3 points, the first being at the fire part, second being at the second part, and the third being at a target, if it isnt what you meant then could you give me an example?

It’s the actual method of making the projectile travel to the points that I want to be as performant as possible. As in, part shoots projectile at another part. Stuff like lerp(), BodyMovers, TweenService, constraints. Are you referring to a module of some sort that handles projectiles and bezier curves?

I use a module I found a while ago which has two functions, a constructor (for settings control points and returning a bezier object) and a bezierObject:Get(t) function and you have to implement the loop yourself, its very performant.

Do you have a link to the module?

had to create the module on my own models because the one i was using made by another person was using an outdated function or something and would error 100% of the time, if you look inside the module script itself there should be some comments that show documentation

Its not for sale, but it was created on my birthday haha

1 Like

Oh sorry let me fix that, ill heart your reply when I put it for sale

1 Like

I see how it works. So when you were making your rocket system what method did you use for the projectile to follow the points? Just a loop that manipulates the rocket’s CFrame?

If I’m correct, the :Get/:GetPoint() function returns a Vector3 value, so I just set the .Position to the return of :Get/:GetPoint(). To make it rotate, you could set the CFrame LookVector to t+0.1 or something like that as long as t is less than 0.9 and it will rotate along the line, I think. I haven’t really explored that yet.
https://www.roblox.com/games/7038281025/PurpleMissileBeziers
Check out this game I made, just click around on the baseplate, i think it requires a mouse.

nvm i think i broke the game but yeah

I liked the projectiles though! And I also see what you were trying to achieve. I’m hiring you for if I make an mmorpg haha because those were stunning. I also think I figured out the solution to my question and I’m gonna experiment with this. I’m thinking of using AlignPosition constraints on all the projectiles which would send a projectile that locks on to the target even while it’s moving.

Oh alr, idek what an alignposition is but by the name it sounds like it makes more sense, and yeah my game was like 1 fps so i could not do anything

You can use rays which originates from a point and shoots to another point. Rapidly firing it is no issue, the only issue you have to worry about is how far you shoot those rays. Shooting 100 rays at 100 studs is better than 10 rays shooting at 1000 studs.

1 Like

Are rays able to move with a target? The projectiles will be covering a short distance fired from a static part to a moving target. I like how rays have no issues with rapid firing.

No, which is why you have to rapidly fire it, just make sure it doesn’t shoot a very far distance or else you’ll suffer from performance issues.