Problem With Offseting FastCast Visual Bullets

I was trying to offset bullets to the fire point with the FastCast module, while the actual raycast origin is HumanoidRootPart/Head’s position. The method is to subtract origin offset from visual origin offset to get vector3 for rendering bullets

--base origin is (HumanoidRootPart.CFrame * CFrame.new(0, 1.5, 0).p
--visualOffset is position of fire point attachment
local VisualOrigin = ((visualOffset or origin) - origin)

CastBehavior.VisualOffset = VisualOrigin
	
if PIERCE_DEMO then
	CastBehavior.CanPierceFunction = CanRayPierce
end
	
CastBehavior.UserData = {
	CastBehavior = CastBehavior
}
	
local simBullet = Caster:Fire(origin, direction, modifiedBulletSpeed, CastBehavior)

Inside OnRayUpdated function, segmentOrigin is modified by adding VisualOffset to it

function OnRayUpdated(cast, segmentOrigin, segmentDirection, length, segmentVelocity, cosmeticBulletObject)
	-- Whenever the caster steps forward by one unit, this function is called.
	-- The bullet argument is the same object passed into the fire function.
	if cosmeticBulletObject == nil then return end
	segmentOrigin = segmentOrigin + cast.RayInfo.VisualOffset
	cosmeticBulletObject.CFrame = CFrame.new(segmentOrigin, segmentOrigin + segmentVelocity)
end

However, the result from the test made bullets’ travel directions inaccurate, although visual origin offsets seemed to look fine.

This is my expectation:

And this is what I get:

I have yet to find a solution. But I would greatly appreciate it if you have any ideas to solve this problem. Thanks.

bullet_offset_test.rbxl (114.8 KB)

It literally just looks like you have a really heavy bullet drop in the second video which is making the visual kinda offset when you spam it

It seems like the bullet direction is being calculated from your character’s head, while the actual projectile is being shot out of the gun’s barrel. You need to calculate the visual projection from a starting position of the end of the gun’s barrel.

Not really. It also happened when there wasn’t bullet drop. The problem here is the travel direction of visual projectile.

The visual projectile direction should rely on visual origin instead of raycast origin, is that what you mean?

I was running your example to check it out but getting these errors

  17:17:58.484  Casting for frame. (x66)  -  Server - ActiveCast:81
  17:17:58.802  Hit something, testing now.  -  Server - ActiveCast:81
  17:17:58.802  Piercing function is nil or it returned FALSE to not pierce this hit.  -  Server - ActiveCast:81
  17:17:58.802  Hit was successful. Terminating.  -  Server - ActiveCast:81
  17:17:58.802  Players.Lord_BradyRocks.Backpack.DebugGun.Server:261: attempt to index nil with 'CosmeticBulletProvider'  -  Server - Server:261
  17:17:58.802  Stack Begin  -  Studio
  17:17:58.802  Script 'Players.Lord_BradyRocks.Backpack.DebugGun.Server', Line 261 - function OnRayTerminated  -  Studio - Server:261
  17:17:58.803  Script 'Players.Lord_BradyRocks.Backpack.DebugGun.FastCastRedux.Signal', Line 112 - function FireSync  -  Studio - Signal:112
  17:17:58.803  Script 'Players.Lord_BradyRocks.Backpack.DebugGun.FastCastRedux.ActiveCast', Line 758 - function Terminate  -  Studio - ActiveCast:758
  17:17:58.803  Script 'Players.Lord_BradyRocks.Backpack.DebugGun.FastCastRedux.ActiveCast', Line 325 - function SimulateCast  -  Studio - ActiveCast:325
  17:17:58.803  Script 'Players.Lord_BradyRocks.Backpack.DebugGun.FastCastRedux.ActiveCast', Line 613  -  Studio - ActiveCast:613
  17:17:58.803  Stack End  -  Studio

And from this comment ‘However, the result from the test made bullets’ travel directions inaccurate, although visual origin offsets seemed to look fine.’ Are you saying the blue ray bullets are not traveling in the correct arc and also do not end up at the correct end point?

But the black marker things are correct? ( Have fired the gun 50 times and trying to understand what you are say… and how can the arcs be the same if their starting points are different? )

Thanks