Bullet not shooting in the correct orientation I want it to be (SOLVED)

If you see in the video below, the bullets of my gun are shot vertically and not horizontally, so as any normal person would, I tried changing the Orientation of the bullet first. Bullets still shot vertically. I saw many people with similar problems but their scripts used .Velocity instead of using RayCast like mine.

I also slowed down the bullets so you can see that they aren’t shooting right.

-- This is a normal Script located in ServerScriptService
-- This is also not the whole script
GunEvent.OnServerEvent:Connect(function(plr, eventtype, tool, startpos, endpos)
	if eventtype == "Shoot" then
		tool:SetAttribute("Ammo", tool:GetAttribute("Ammo") - 1)
		GunEvent:FireClient(plr, "Shoot")
		local Char = plr.Character
		local Direction = (endpos - startpos).Unit*1000
		local RayCastParamss = RaycastParams.new()
		RayCastParamss.FilterType = Enum.RaycastFilterType.Exclude
		RayCastParamss.FilterDescendantsInstances = {tool:GetDescendants(), Char:GetDescendants()}
		
		local RayCast = workspace:Raycast(startpos, Direction, RayCastParamss)
		
		if RayCast then
			local BulletClone = Bullet:Clone()
			BulletClone.Parent = game.Workspace
			BulletClone.Position = startpos
			BulletClone.CFrame = CFrame.new(startpos, startpos + tool.MainTurret.Barrel.CFrame.LookVector)
			
			local Duration = (endpos - startpos).Magnitude / 135
			
			local BulletTween = TS:Create(BulletClone, TweenInfo.new(Duration, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Position = endpos})
			BulletTween:Play()
			SoundServ.m2_browning_fireend:Play()
			BulletTween.Completed:Wait()
			BulletClone:Destroy()
			
			
			if RayCast.Instance.Parent:FindFirstChild("Humanoid") then
				RayCast.Instance.Parent.Humanoid:TakeDamage(Dmg)
				BulletTween.Completed:Wait()
				BulletClone:Destroy()
			end
		end
		
	elseif eventtype == "Reload" then
		tool:SetAttribute("Ammo", tool:GetAttribute("MaxAmmo"))
		GunEvent:FireClient(plr, "Reload")
	end
end)

So, what exactly is the Bullet? Is it a part? Does it have descendants? Children?

1 Like

It is a part in ServerStorage that the gun shoots, it has children which is just bullet tracer effect.

1 Like

You should check which direction is the part’s front face. It’s likely that the mesh it is using does not have the bullet mesh pointing toward the front face of the part.

1 Like

Adjust/rotate the CFrame.

			BulletClone.CFrame = CFrame.new(startpos, startpos + tool.MainTurret.Barrel.CFrame.LookVector) * CFrame.Angles(0,0,math.rad(180)) --Adjust accordingly

That does work for meshes but the bullet im using is a union.

That works but only when I am shooting straight ahead, because now this happens.

CFrame code looks alright.

The main feeling I get is that the turret is controlled locally perhaps by motor6d or CFrames but this change is not replicated to the server hence the bullet direction is wrong.

You should debug this lookvector variable further and see if it is changing as it should be.

Just like @dthecoolest said, it probably isn’t replicated, but since you’re already passing endpos through the remote event you can just use CFrame.lookAt(startpos,endpos) and adjust the rotation in case your Union’s got weird face directions just like @iammr_oofoof said by using * CFrame.Angles(0,0,math.rad(180)) to adjust accordingly

2 Likes

So um I have gotten closer but idk if I did it right because I replaced this

BulletClone.CFrame = CFrame.new(startpos, startpos + tool.MainTurret.Barrel.CFrame.LookVector)

With this:

BulletClone.CFrame = CFrame.lookAt(startpos, endpos) * CFrame.Angles(0,0,math.rad(180)) --Adjust Accordingly

I also havent used CFrame.Lookat like ever until now

That should be fine I guess.
Also CFrame.Lookat(pos,posToLookAt) is kinda the same as CFrame.new(pos,posToLookAt), you could use CFrame.new if you feel more comfortable with it.

Thank you I think all i have to do is just adjust the CFrame.Angles() part

Edit: I eventually got it! thank you guys

2 Likes

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