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
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.
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.
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
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
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
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.