Basically I’ve been trying to do the bullet path, currently I’m using beams so I want it to move fast but for the other players to see the path a bit, I don’t know whether to use TweenService, LinearVelocity or Vectorforce, NOBODY ANSWERS THESE QUESTIONS FROM THE THE EXACT WAY ONE NEEDS AND THAT’S WHY I MAKE THIS SUBJECT.
Also, if you tell me to use linearvelocity, tell me how since I used it but when he launches the bullet it follows the direction but it’s as if the breeze makes it change position and makes it spin like crazy.
please help me
If you have doubts, just ask, I know that there are people who do not understand my subject because of my way of expressing myself.
if you aren’t trying to physically simulate the bullet for some game mechanic, I would recommend using TweenService or lerping. The easiest route is to move an anchored part along a path. So like, if you have the position of the weapon, and the position of where they shot, you could tween with:
local TweenService = game:GetService("TweenService")
--[...wherever the bullet is being shot..]
local bullet = --the bullet instance
local startPosition = --where the weapon is being fired from, in CFrame
local endPosition = --where they're shooting at, in CFrame
bullet.CFrame = startPosition -- start by placing the bullet at the beginning
TweenService:Create( --create a new tween
bullet, --the instance to be tweened, here, the bullet
TweenInfo.new(1), --look into TweenInfo for customizing stuff, but with just '1' it will take 1 second to complete a linear tween
{CFrame = endPosition} --the property of the instance to be tweened, here we want to tween bullet.CFrame
):Play() --play the tween to begin moving the bullet from where it was, to endPosition
hey thanks I heard that TweenService used a lot of memory and that linear velocity didn’t but there is no way for the bullet to go straight without it going crazy in chaos that there is no way to use LinearVelocity which is more optimized TweenService or :Lerp
a and another thing I use rays and I don’t know what to put in the endposition variable.
edit: if in the CFrame value I add a position like mouse.Hit.Position or Ray.Position it says that a vevtor3 is not valid or something like that and when the player shoots at the sky what value should i use?
other edit:I think I’ll change the part where it shoots instead of sending to the server: Mouse.Hit.Postion
, i am sends the midpoint of the camera
you’d reference the RaycastResults’ property for position & normal. If how the bullet faces along the path doesn’t matter the tween could be simplified to just the Position property.
this could be benchmarked by the microprofiler but imo this is incorrect info. LinearVelocity has to be solved by the physics engine every physics frame, but tween doesn’t, as it’s an anchored part. I wouldn’t worry about memory handling that strict that you need to weigh using tweens or not.
If you don’t get a RaycastResult from the raycast I would create a CFrame/position at the weapon’s LookVector times some magnitude like 100 so that the bullet still goes some distance
referencing Mouse.Hit isn’t proper raycasting, I would look into Raycasting | Roblox Creator Documentation
unless intended for gameplay relying on mouse.hit would allow players to shoot through walls, ceilings, anything they can get their camera around
seI know that bodyvelocity is obsolete but I saw that it gives me the solution that I need just like TweenService but the problem is that it is already obsolete and I don’t know if one day it won’t be able to be used anymore
Anything marked “Deprecated” by Roblox is no longer updated alongside any engine updates they do, so there is no guarantee that they will work in the future. I would avoid using any deprecated features
Personally I use, just change the position for the bullet like this;
Main function;
local bulletStart = tool.FirePart.Position
-- Calculate the direction based on the target position
local direction = (targetPosition - bulletStart).Unit
local bullet = createBullet(bulletStart, direction, bulletSpeed)
local velocity = direction * bulletSpeed
local updateRate = 0.01
local timeElapsed = 0
local bulletLifetime = 5 -- bullet will be removed after 5 seconds
while timeElapsed < bulletLifetime do
local breakBool = updateBullet(bullet, velocity, updateRate)
if breakBool == true then
break
end
velocity = velocity + gravity * updateRate
timeElapsed = timeElapsed + updateRate
runservice.Stepped:Wait()
--wait(updateRate)
end
The function above calculates the projection and then the updateBullet function looks something like this;
local function updateBullet(bullet, velocity, dt)
local startPosition = bullet.Position
local endPosition = startPosition + velocity * dt
bullet.Position = endPosition
To account for any collision I use raycasting as it is most accurate.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.