Beam bullet tracer position of origin is completely off

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Fix my beam bullet tracer origin position.

  2. What is the issue?
    I tried to use Raycast for a gun and wanted to make a bullet tracer for it for whatever reason it doesn’t work the position where the bullet should come out is completely off

How it look in-game

  1. What solutions have you tried so far? Tried switching from server to client still have the same issue.

The position I use is taken from the part cframe which I weld with the gun.
I made sure the cframe/position was in the right place. however, when I switch from client to server and then back to the client via the studio feature the position is correct and works just fine(it also fixes itself after some time has passed)

local ViewRayOrigin = workspace.CurrentCamera.CFrame.Position
				local gunOrigin = game.Workspace:FindFirstChild("armsViewmodel")
				if not gunOrigin then	repeat print("No gun") wait() until gunOrigin	end
				local originPos=gunOrigin["Glock"]["BulletOrigin"].Position

				local Range = 1500

				local Params = RaycastParams.new()
				Params.FilterDescendantsInstances = {Players.Character,workspace.Effect}


				local ViewRayDirection = (workspace.CurrentCamera.CFrame.LookVector + Vector3.new(math.random(-10,10)/500,math.random(-10,10)/500,math.random(-10,10)/500)) * Range 
				local ViewRay = workspace:Raycast(ViewRayOrigin, ViewRayDirection, Params)

				if ViewRay and ViewRay.Position then
					local distance = (originPos - ViewRay.Position).Magnitude

					local p = game.ReplicatedStorage.BulletTracer:Clone()
					p.Anchored = true
					p.CanCollide = false
					p.CanQuery=false --neat feature so you wont be shooting the bullets incase raycast fails
					p.CanTouch=false
					p.Size = Vector3.new(0.1, 0.1, distance)
					p.CFrame = CFrame.new(originPos,ViewRay.Position)*CFrame.new(0, 0, -distance/2)
					p.Attachment1.Position = Vector3.new(0,0,-distance/2)
					p.Attachment2.Position = Vector3.new(0,0,(distance/2))
					p.Parent = workspace.Effect

					game.Debris:AddItem(p,4)
					game.TweenService:Create(p.BulletTrace,TweenInfo.new(0.8,Enum.EasingStyle.Quart),{Width0 = 0}):Play()
					game.TweenService:Create(p.BulletTrace,TweenInfo.new(0.8,Enum.EasingStyle.Quart),{Width1 = 0}):Play()
				end
2 Likes

I would recommend setting Attachment1.WorldPosition to BulletOrigin.Position. The Position property is treated as an offset position relative to the Attachment’s parent position. I hope this helps!

local armsViewModel = workspace:WaitForChild("armsViewmodel")
local glock = armsViewModel:FindFirstChild("Glock")

local bulletOrigin = glock:FindFirstChild("BulletOrigin")
p.Attachment1.WorldPosition = bulletOrigin.Position
2 Likes

still got the same result.
this video is me using the solution you gave me so maybe it could help. thanks for replying.
also, the first code also has the same result as in this video(kinda)

2 Likes

I’m not sure what the entire layout of your script is, but i think you should reiterate the ViewRayOrigin before setting the raycast, since storing values such as Vector3 will remain static until updated.

2 Likes

I may be getting confused here, but I’m noticing the bullet rays acting as desired at the 0:08?

2 Likes

I already said that the issue fix itself only when I switched from client to server and then back to client again in the studio.

2 Likes

It’s a one-time use value store per shot so I don’t think that’s the issue.
(Tried it)

VERY MAYBE this might be the fix, but I just changed some things up a little bit.

local ViewRayOrigin = workspace.CurrentCamera.CFrame.Position
local gunOrigin = game.Workspace:FindFirstChild("armsViewmodel")
if not gunOrigin then	repeat print("No gun") wait() until gunOrigin	end
local originPos=gunOrigin["Glock"]["BulletOrigin"].Position

local Range = 1500

local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {Players.Character,workspace.Effect}


local ViewRayDirection = (workspace.CurrentCamera.CFrame.LookVector + Vector3.new(math.random(-10,10)/500,math.random(-10,10)/500,math.random(-10,10)/500)) * Range 
local ViewRay = workspace:Raycast(ViewRayOrigin, ViewRayDirection, Params)

if ViewRay and ViewRay.Position then
	local distance = (originPos - ViewRay.Position).Magnitude
	
	local p = game.ReplicatedStorage.BulletTracer:Clone()
	p.Anchored = true
	p.CanCollide = false
	p.CanQuery=false --neat feature so you wont be shooting the bullets incase raycast fails
	p.CanTouch=false
	p.Size = Vector3.new(0.1, 0.1, distance)
	p.CFrame = CFrame.new(originPos,ViewRay.Position)*CFrame.new(0, 0, -distance/2)
	p.Attachment1.Position = Vector3.new(0,0,-distance/2)
	p.Attachment2.Position = Vector3.new(0,0,(distance/2))
	p.Parent = workspace.Effect
	
	game.Debris:AddItem(p,4)
	game.TweenService:Create(p.BulletTrace,TweenInfo.new(0.8,Enum.EasingStyle.Quart),{Width0 = 0}):Play()
	game.TweenService:Create(p.BulletTrace,TweenInfo.new(0.8,Enum.EasingStyle.Quart),{Width1 = 0}):Play()
end
1 Like

Same exact issue, It also fixes itself when switching between client and servers too. ;(

1 Like

Did you check outside of roblox studio?

1 Like

Yep, Still get the same issue. I also try resetting the character after shooting still does not fix it.
I also updated the code.

1 Like

How do you insert the armsViewmodel, is it pre-inserted in server?
Because if that is the case, it might be a network ownership issue.

Best solution at that point is to maybe have the armsviewmodel parented to something like your script, and then be parented to camera, whilst also keeping a global value to make sure you wont have to rewrite the same thing over and over.

local camera=game.Workspace.CurrentCamera
local armsViewModel=script:FindFirstChild("armsViewmodel") or camera:FindFirstChild("armsViewmodel")

armsViewModel.Parent=camera --usual case with these FPS views is to parent it to the camera

just try adapting your script in this logic.

Both the armsViewmodel and the bullet tracer script are on the client side (I intended to make a separate server-side bullet tracer later) and the armsviewmodel is just chilling(parented) in the workspace and I make the Cframe of the humanoidrootpart of the ViewModel set to camera Cframe every frame.

Then honestly I have no other idea other than instead of using the viewmodel for the originPos you do something like

Camera.CFrame*CFrame.new(0,-0.1,-0.5)

Even though it’s quite a hassle to use this method but it does work fine, Thank you very much. also don’t forget the (Cframe).position

EDIT: I finally know the cause of it, it is because the view model HumanoidRootPart is not anchored so even though the model seems to follow your camera without fails, the physics don’t think so causing the origin of the bullet to goes down with the ViewModel.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.