Attachment's LookVector not updating?

Hey everyone. I’m working on an ffa game and was working on bullet movement, and wanted the bullets to go in the direction the lookvector is facing, but the gun always shoots at the same area?

Video:


(As you can see, it fires towards the origin, instead of the front of the muzzle)

Image of muzzle attachment:

Any idea what’s going on?

(By the way, this is all running on the client, server sided manipulation will be added later)

1 Like

Could I see the script that controls the gun?

2 Likes

Its a module that’s supposed to be compatible for a custom gun system, I’ll send you the projectile logic:

local bullet = repStorage.projectile_assets:FindFirstChild("bullet")
				bullet = bullet:Clone()
				bullet.Parent = workspace.projectiles

				local origin = self.curwep.root.muzzle.WorldPosition
				local direction = -self.curwep.root.muzzle.WorldCFrame.LookVector

				bullet:PivotTo(CFrame.new(origin, direction)) -- Where I set the bullet CFrame
				bullet.Anchored = false
				bullet.CanCollide = false

				local loop
				local spreaded = false

				loop = RunService.RenderStepped:Connect(function(dt)
					bullet.CFrame *= CFrame.new(0, 0, -7 * (dt * 120))
					if not spreaded then
						bullet.CFrame *= CFrame.Angles(math.rad(math.random(self.settings.spreadOffset.min, self.settings.spreadOffset.max)), math.rad(math.random(self.settings.spreadOffset.min, self.settings.spreadOffset.max)), 0)
						spreaded = true
					end

					if (bullet.Position - origin).magnitude > 5000 then
						bullet:Destroy()
						loop:Disconnect()
					end

				end)

(sorry the indenting is off, its part of a repeat and a for loop)

2 Likes

The LookVector of a CFrame is a normalized vector with the same orientation of a part, so if you add it to the Position of a part, its like moving it forward in its direction by a magnitude of one. If you want the bullets to shoot forward, I would recommend having the bullets point in the direction of the character when shooting, then you can apply the spread rotation, and have the bullets move forward by their LookVector.

1 Like

Why not use the attachment’s lookvector? Is there a specific reason?

1 Like

The LookVector of the attachment is based on its orientation, not its position. You could use its LookVector if you have the attachment face the same orientation as the character.

1 Like

Yeah, it is, refer to the image below. Thats the problem.

1 Like

The arrow refers to its front face, or the direction its pointing in

1 Like

Based on some testing I did, it looks like the attachment’s yellow arrow isn’t the direction it is facing. The actual direction is perpendicular to both arrows as seen in this screenshot.

No idea why it is like this but yeah.
Update: Sorry about all the edits. I was constantly second guessing myself.

1 Like

Instead of this, I would make it move forward by the bullet’s LookVector:

bullet.CFrame += bullet.CFrame.LookVector

You can edit the speed however you want by multiplying the LookVector.

1 Like

Sorry for the late response, but in the image, the lookvector is the green conical arrow. I use a plugin that shows the faces of the vectors. I should probably tell you that this is all client sided, as server sided manipulation will be added later. Does that affect the lookvectors?

1 Like

Client-side or Server-side shouldn’t affect the LookVectors.

1 Like

Why is this? characters

1 Like

Ill keep trying other methods. Let me check using the torsos look vector real quick. Will update soon

1 Like

Seems to be the same even with the torso’s lookvector. Is this a bug or am I doing something wrong here??

1 Like

I think this could be the issue actually. LookVector is a vector, not an orientation. I would replace that with

bullet:PivotTo(self.curwep.root.muzzle.WorldCFrame)
2 Likes

Huh, seems to be working. Weird, but thanks a lot for your help!

2 Likes

I think the best way to explain this is by explaining how CFrame.new(positionA, positionB) works.
positionA is the position the instance is set to.
positionB is the position the instance looks at.

Because LookVector is a normalized vector, (meaning it has a magnitude of one from the origin) the bullets were pointing at the LookVector, which was essentially at the origin.

1 Like

Yeah, but looking at the documentation, lookvector should have worked, since its parented to an object, not just the origin.


(Pulled from the documentation)

1 Like

Thats when you add it. When you add two vectors together, each respective component gets added.
For example, lets say V1(x1, y1, z1) = (3, 5, 8) and V2(x2, y2, z2) = (16, -5, 1)

V1 + V2 = (x1 + x2, y1 + y2, z1 + z2) = (19, 0, 9)
And when it is applied to the LookVector, let’s say Part.Position = (10, 10, 10) and Part.Orientation = (0, 90, 0).

Part.CFrame.LookVector = (-1, 0, 0) which has a magnitude of one respective to the origin.
adding the LookVector to the Part will give (9, 10, 10).

1 Like