I’m currently having issues with FastCast module, as of right now my guns maximum distance range doesn’t seem to be very accurate, for example I set my max range distance to 50 studs, the bullet seems to go past it up to 80-95+ studs, or even less than the max range is, basically double the range, this depends on the bullet speed, if I set the speed to something like 100 studs per second it will only go a little over, but if I have it something higher like 2-5k it goes well beyond that.
It could be that the bullet is traveling fast enough that one frame is hundreds of studs, and when checking to see if it passes the boundry, by the next frame it will be well beyond the boundary because of its speed.
There are a few possible solutions to this issue. The first would be to increase the accuracy of the FastCast module. This can be done by adjusting the accuracy settings, adjusting the bullet speed, or even increasing the number of bullets being fired at the same time. Another possible solution is to adjust the maximum distance range by adding an extra layer of range between the minimum and maximum distances that the bullets can travel. This can be done by increasing the distance between the two points or adding an extra distance layer between the two. Finally, you may want to consider using a different module for your gun, as some modules may be more accurate than others.
You need to make sure that the ray cast itself isn’t going past the maximum distance. Check to make sure that each raycast size plus the bullets current distance is not greater than your maximum distance. If it is, then subtract the difference from the length of your raycast.
Not sure what I can send, this is using a public module, this is what it’s using to move the bullet.
local function GetPositionAtTime(time: number, origin: Vector3, initialVelocity: Vector3, acceleration: Vector3): Vector3
local force = Vector3.new((acceleration.X * time^2) / 2,(acceleration.Y * time^2) / 2, (acceleration.Z * time^2) / 2)
return origin + (initialVelocity * time) + force
end
-- A variant of the function above that returns the velocity at a given point in time.
local function GetVelocityAtTime(time: number, initialVelocity: Vector3, acceleration: Vector3): Vector3
return initialVelocity + acceleration * time
end
local function GetTrajectoryInfo(cast: ActiveCast, index: number): {[number]: Vector3}
assert(cast.StateInfo.UpdateConnection ~= nil, ERR_OBJECT_DISPOSED)
local trajectories = cast.StateInfo.Trajectories
local trajectory = trajectories[index]
local duration = trajectory.EndTime - trajectory.StartTime
local origin = trajectory.Origin
local vel = trajectory.InitialVelocity
local accel = trajectory.Acceleration
return {GetPositionAtTime(duration, origin, vel, accel), GetVelocityAtTime(duration, vel, accel)}
end
I actually don’t know, I am not this advanced at scripting, I can understand this code somewhat, but not really, that’s why I used this module since it’s easy and fast, and I just have to use a few lines to fire off a ray, I don’t know what exactly is causing the ray to fluctuate so much.
The trajectory.EndTime value is the most important value here because it determines at what time position you are calculating the position. However, the math here still doesn’t add up. You don’t divide at^2 by 2 in the position function, and force is not added to the origin plus velocity offset to determine position. Why not just set the velocity of your projectile once instead of recalculating its position each frame? You can still apply a deceleration each frame to simulate air resistance if you wanted without all of this extra complexity.
I didn’t write this code, this module isn’t mine, I think that is because there’s a thing in the module called onLengthChanged, which fires every time it is updated, which is the reason why it might be that way because it’s designed to have a part visibly show with speed to simulate a bullet.