What method should I use to move my bullet from point A to B

Would that not go in a straight line?

Thats what you can probably achieve with physics and combining some constraints. Tweening is really not recommended for your projectile since the path is undetermined and using tween service you need a set position.

1 Like

Getting the current CFrame of the part in each iteration should stop it from going in a straight line as it modifies the interpolation boundaries.

1 Like

Quadratic lerps allow your projectile to move in a curve like path. Similar to tween service and requires 3 set positions instead.

1 Like

It looks like I have 3 different options to try!
Quadratic Lerping, @12345koip’s method of Lerping, and using body movers.

I’m going to look into all these options and see which one works best for me!

1 Like

This is probably a confusing thing to understand, but couldn’t you realistically perform this math calculation to achieve this curve?

a + (b - a) * c

Used an external site to get the example, but I’m pretty sure this is how must people do it.

image

1 Like

Maybe I could perform that when the bullet gets close enough to the player but it might look strange

Edit: in that image and code example, do you know what letter is what number?

1 Like

I’m pretty sure you could lower both values a and b to make C higher and more aggressive.

abc = 123

Now that I look at it, this suggestion is more useful for a projectile with falloff, rather than a magnet.

(also I should note that the numbers work off decimal scales from 0 to 1. Making specific decimals higher or lower affects the curve)

I’m still pretty new to the Bezier curve stuff so I might be inaccurate a bit, so I’m hoping someone with more experience can chip in here.

1 Like

I saw this earlier:
https://devforum.roblox.com/t/how-to-make-lerp-bezier-curves-with-runservice-chapter-1/1788452

here is a masterpiece of epic proportions and the image of what i want

shoot

pink circle is enemy
red circle is me
red line is normal bullet trail
green line is the effect i want to achieve, a magnetic bullet effect

this is so cringe lol

Magnets have radius which determines if they are attracted to something, you can just do a magnitude check to check if a target is in range and adjust the trajectory of the projectile accordingly.

1 Like

I thought the best way to do guns is by firing a ray to detect if it was hit and just have the bullets be there purely as VFX

1 Like

A solution for simulating the projectile with a realistic ballistic kinematics approach:

Equation for finding Position (p1) given initial position (p0), initial velocity (v0), time (t), and constant acceleration (a) in kinematics:
p1 = (p0) + (v0)(t) + (1/2)(a)(t^2)

For a normal ballistic projectile, the way I do it is:

At inception:

  1. Record start time
  2. Record start position
  3. Record start direction
  4. Record starting velocity

On heartbeat:

  1. Get time in flight (current time - start time)
  2. Check if total time in flight is greater than some max value to avoid projectiles living forever and never hitting anything
  3. Plug initial velocity, initial position, gravity, and time in flight into the kinematics equation to solve for current position
  4. Shapecast from last position to new position to find obstacles
  5. If obstacle, apply damage and destroy projectile. If no obstacle, continue.
  6. Update the position of the projectile to the new position
  7. Save the new position as “last” position for the next heartbeat to compare

This assumes a constant acceleration (gravity) is the only force acting on it. But if you want “aimbot”, e.g. curve projectiles toward nearby targets, then you’ll need to introduce another force acting on it. A couple changes would need to happen:

Since the path isn’t pre-determined anymore, you can’t use the position and velocity at inception for the whole flight anymore. Instead, use the previous frame’s velocity and position as the new v0/p0, and use time since last frame instead of total time in flight for t.

You still have a constant gravity, but in order to introduce a curve toward enemies, you can find the closest enemy and add another acceleration force in the direction of that enemy, scaled exponentially by how close the distance to that enemy is (e.g. the closer the enemy, the stronger the curve force).

The strength of this “curve” force (F) on the projectile can be imagined as a gravitational force (G) acting on the Mass of the character (M1) and the Mass of the projectile (M2) scaled by the Distance between the two (D). Plug these variables into the equation for gravitational force:
F = (G × M1 × M2) / (D^2)

In order to achieve a fun “curve”, you’d probably want a pretty high G value in this case rather than using the normal gravity constant. You can make up values for M1 and M2, or omit them entirely if you don’t care about simulating different curves based on different targets.

So if you assume every enemy and projectile has a constant mass, just use F = G / D^2 where changing G is the way that you tune the strength of the curve.

2 Likes

This is so incredibly phenomenally smart that my two brain cells have a difficult time even comprehending it :face_with_peeking_eye:

It might take me some time to work through this but luckily my game is a top down shooter so I can just forget the Y axises entirely, and along with it, gravity!

TY


I made a 3d prototype and this is way too cool haha

1 Like

DUDE, it’s like you pulled the idea straight from my brain!

Would it be cool if you uncopylocked it so I can look around and see how you did it and make it 2D?
If not that’s totally cool

ProjectileAimbot.rbxl (79.9 KB)

Here’s the file.

Disclaimer

This file is provided as-is for learning purposes only and not for commercial use; that is, please do not re-use my 2d or 3d assets or directly copy/paste my code into a project that will earn any money. But you may take any learned concepts from reading it and write your own code.

It’s pretty over-engineered to be useful as a reference, and you probably shouldn’t use OOP for a projectile because of the metatable overhead, but for experimental purposes this is fine.

One improvement would be in the target picking algorithm. Instead of picking the closest target, pick the target that is closest on the forward path of the projectile.

1 Like

Where did your learn to code?

You are extremely good at coding and game dev in general

Thank you. Most of my learning happened through years of developing on roblox, but I also went to university for it later.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.