# Problems with Bullet Orientation

I’m creating an FPS game, and I have a functional gun system, however, whenever you shoot, the bullet sometimes has the wrong orientation (depending on where you’re facing)

This can probably be fixed easily, but I have no idea how.

Code regarding the bullet:

``````			local MidPoint = PlayerPos + RaycastResult.Position/2
local Part = Instance.new("Part")
Part.Anchored = true
Part.Size = Vector3.new(0.2,0.2,1.5)
Part.Material = Enum.Material.Plastic
Part.Transparency = 0
Part.CanCollide = false
Part.Parent = game.Workspace
Part.Position = Tool.Handle.Position
Part.Name = "Bullet"
Part.Color = Color3.new(1, 1, 0)

Part.CFrame = CFrame.lookAt(PlayerPos, MidPoint)

local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(Distance/300,Enum.EasingStyle.Linear,Enum.EasingDirection.In)
local Tween = TweenService:Create(Part,tweenInfo,{ Position = RaycastResult.Position * 1.01})
Tween:Play()
``````

I am using raycasts to get the position of where the player shot (using Player.Mouse)

Video showing the problem:
robloxapp-20230727-2015415.wmv (2.9 MB)

1 Like

Try rotating it using CFrame.Angles

Thanks for your reply, but how exactly would I use CFrame.Angles? (Never used it before)

So basically CFrame.Angles is a way to manipulate something’s rotation

In your case it looks like your a part needs to be rotated 90 degrees on the Y axis

So you would multiply the cframe like so

``````Part.CFrame = CFrame.lookAt(PlayerPos, MidPoint) * CFrame.Angles(0,math.rad(90),0)
``````

If your curious what math.rad basically you need to convert the angle to radians so tii works properly

Edit : Sorry so it actually looks like the way your making the bullet orient when you use the LookAt function, try making it look at where your camera is facing or the mouse’s lookvector

How can I do this? Sorry I’m bad at using CFrames.

Youd have to pass the mouse object through the remote but you could
try doing this

``````local Part = Instance.new("Part")
Part.Anchored = true
Part.Size = Vector3.new(0.2, 0.2, 1.5)
Part.Material = Enum.Material.Plastic
Part.Transparency = 0
Part.CanCollide = false
Part.Parent = game.Workspace
Part.Position = Tool.Handle.Position
Part.Name = "Bullet"
Part.Color = Color3.new(1, 1, 0)

Part.CFrame = CFrame.new(PlayerPos, mouse.CFrame.LookVector)

local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(Distance / 300, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local Tween = TweenService:Create(Part, tweenInfo, {Position = RaycastResult.Position * 1.01})
Tween:Play()
``````
1 Like

Does that exist? I think mouse has no CFrame property. Do you mean Mouse.Hit.LookVector?

Yeah sorry thats what I meant

rghtrfedetv

1 Like

I’m not sure if I did something wrong, but it’s still not facing the right direction. If you don’t have any other ideas on how to solve this problem, it’s fine since its not necessarily needed. Thanks for your time.

Code I used:
Server Script:
Part.CFrame = CFrame.new(PlayerPos, LookVector)

Local Script:
local LookVector = Mouse.Hit.LookVector

1 Like

For anyone reading this post, I have fixed it by:

Changing This:
Part.CFrame = CFrame.lookAt(PlayerPos, MidPoint)

To This:
Part.CFrame = CFrame.new(Tool.Handle.Position - Vector3.new(0,0,0.5), RaycastResult.Position)

1 Like

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