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)
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
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