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

Heyo!

Right now I am making a gun using FastCast and am wondering what the best way is to move a bullet from the gun muzzle to my mouse position. I have looked around and saw 3 options. Lerping, tweening, and using bodymovers.

I have a future plan in my game to have magnetized bullets that sort of “Aimbot” towards the player like in this post

Overall I want your guys opinion what the best option is and if possible what method I would have to use if I want magnetized bullets

3 Likes

Tweening is the easiest way

4 Likes

adjusting their position every frame using runservice.heartbeat() is probably the most optimal way and it also depends on your layout. Your best bet is to have the hitbox on the client who sent it. Server validating the hit by doing a sanity check (if the clients hitbox actually hit a humanoid and ifs the clients position match up so theyre not hitting the humanoid too far away or not even facing the humanoid). And projectile motion and effects fired on all clients.

5 Likes

With tweening though from what i’ve seen makes the tweened part unable to move from anything else so making a magnet effect would be impossible

2 Likes

if you need a magnet effect for your bullet use a cframe loop to move it instead

1 Like

If I wanted to do a magnet effect so the bullet arcs towards players. what would be the best way to do that? With BodyMovers?

1 Like

Ohh if your using roblox physics instead then dont follow my earlier advice. Using roblox physics for projectiles can be a little complicated since you may need to make the projectile on the server instead, but you can also make the network ownership of the projectile to the client to help this. And the hitbox may also need to moved to the server. Since it doesnt have a predicted path you cannot really handle the projectile motion on all clients since its undetermined (either target moves or anything happens to the projectile).

For your case using body moves like align position or align orientation is probably your best bet but there are also more constraints that you probably need to use.

2 Likes

I have no clue how I would code a realistic arc that feels like the bullet is getting magnetized towards the player. if I knew how to do that I could figure out ow to get the needed Cframes

Lerp it. That’d be the best way to curve it.

local start: CFrame = --start CFrame
local target: BasePart = --target part

for i = 1, 10, 1 do
    local alpha = i / 10
    local current = start:Lerp(target.CFrame, alpha)
    bullet.CFrame = current
    task.wait(0.01)
end
1 Like

As of right now I haven’t decided if I’m going to use roblox physics or Tweening or something else yet. The one problem is how do have two forces on the bullet. The force from the bullet going forward, and the force of the bullet going towards the player. If you combine those two forces you should get a curve towards they player

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