Bullet is not going where mouse is located at

Hello I’m having a rare condition where my bullet isn’t going where I want,and It’s actually bouncing in very weird way and going towards a position which is not even has to do with mouse position.
Please If anyone could help,It’s appreciated.

Screenshot for reference

1 Like

Try providing me the script and I’ll try to help you.

2 Likes

Sure,here you go.

Functions["On Bullet Effect"] = function (CurrentGun : Tool,CurrentGunInfo : any,Shoot_Streak : number,BounceCount : number) : boolean
	BounceCount = 0 or BounceCount
	if BounceCount > 5 then return false end
	
	local Bullet = Instance.new("Part",Replicated_Storage)
	Bullet.CanCollide = false
	Bullet.Anchored = true
	Bullet.Transparency = 1
	Bullet.Name = "Bullet"
	Bullet.Shape = Enum.PartType.Block
	local CurrentPiercing = 0
	Bullet.Size = Vector3.new(1,1,1)
	local StartAttachment = Instance.new("Attachment",Bullet)
	StartAttachment.Name = "Start"
	StartAttachment.Position = Vector3.new(0,0,-2)
	local EndAttachment = Instance.new("Attachment",Bullet)
	EndAttachment.Name = "End"
	EndAttachment.Position = Vector3.new(0,0,2)
	local Effect = Instance.new("Beam",Bullet)
	Effect.Attachment0 = StartAttachment
	Effect.Attachment1 = EndAttachment
	Effect.Width0 = 0.25
	Effect.Texture = "rbxassetid://131924954033556"
	Effect.Transparency = NumberSequence.new(0,1)
	Effect.Width1 = 0.05
	Effect.Segments = 100
	Effect.TextureSpeed = 1
	Effect.LightInfluence = 1
	Effect.LightEmission = 1
	Effect.TextureLength = 5
	local Sequence = ColorSequence.new({
		ColorSequenceKeypoint.new(0,Color3.fromRGB(255, 203, 83))
		,
		ColorSequenceKeypoint.new(0.5,Color3.fromRGB(255, 116, 35))
		,
		ColorSequenceKeypoint.new(1,Color3.fromRGB(255, 70, 70))
	})
	Effect.Color = Sequence
	Effect.FaceCamera = true
	Bullet.Parent = workspace

	local Origin = CurrentGun:FindFirstChild("FirePoint",true).WorldPosition
	local Parameters = RaycastParams.new()
	Parameters.FilterType = Enum.RaycastFilterType.Exclude
	local Blacklist = {Player.Character}
	for _,v in workspace:GetChildren() do
		
		if v:IsA("BasePart") and v.Name == "Bullet" then
			
			table.insert(Blacklist,v)
			
		end
		
	end
	Parameters.FilterDescendantsInstances = Blacklist

	local Res = workspace:Raycast(Mouse.UnitRay.Origin,Mouse.UnitRay.Direction * 1000,Parameters)

	local MousePosition3D = nil

	if Res then

		MousePosition3D = Res.Position

	else

		MousePosition3D = Mouse.Hit.Position

	end

	local FirePoint : Attachment = CurrentGun:FindFirstChild("FirePoint",true)
		
	local Velocity = (MousePosition3D - FirePoint.WorldPosition).Unit * 250
		
	print(Velocity)

	Bullet.Position = FirePoint.WorldPosition


	task.spawn(function()
		while true do
			local DeltaTime = RunService.Heartbeat:Wait()
			Bullet.Position += Velocity * DeltaTime
		end
	end)
	
end

I sent the script,you can check it out

Again any help is appreciated.

This is easy to fix! Move the bullet where the mouse is. Make sure to mark this as the solution.

1 Like

Hmm, I think this is just direction without that 1000, this might fix your code chump
Send in a video

1 Like

What shall I do though,at this point I’m really confused.

Current code is like this by the way.

Is the bullet anchored? It better be or :mad:

1 Like

I actually changed it nevermind.

Functions["On Bullet Effect"] = function (CurrentGun : Tool,CurrentGunInfo : any,Shoot_Streak : number,BounceCount : number) : boolean
	BounceCount = 0 or BounceCount
	if BounceCount > 5 then return false end
	
	local Bullet = Instance.new("Part",Replicated_Storage)
	Bullet.CanCollide = false
	Bullet.Anchored = true
	Bullet.Transparency = 1
	Bullet.Name = "Bullet"
	Bullet.Shape = Enum.PartType.Block
	local CurrentPiercing = 0
	Bullet.Size = Vector3.new(1,1,1)
	local StartAttachment = Instance.new("Attachment",Bullet)
	StartAttachment.Name = "Start"
	StartAttachment.Position = Vector3.new(0,0,-2)
	local EndAttachment = Instance.new("Attachment",Bullet)
	EndAttachment.Name = "End"
	EndAttachment.Position = Vector3.new(0,0,2)
	local Effect = Instance.new("Beam",Bullet)
	Effect.Attachment0 = StartAttachment
	Effect.Attachment1 = EndAttachment
	Effect.Width0 = 0.25
	Effect.Texture = "rbxassetid://131924954033556"
	Effect.Transparency = NumberSequence.new(0,1)
	Effect.Width1 = 0.05
	Effect.Segments = 100
	Effect.TextureSpeed = 1
	Effect.LightInfluence = 1
	Effect.LightEmission = 1
	Effect.TextureLength = 5
	local Sequence = ColorSequence.new({
		ColorSequenceKeypoint.new(0,Color3.fromRGB(255, 203, 83))
		,
		ColorSequenceKeypoint.new(0.5,Color3.fromRGB(255, 116, 35))
		,
		ColorSequenceKeypoint.new(1,Color3.fromRGB(255, 70, 70))
	})
	Effect.Color = Sequence
	Effect.FaceCamera = true
	Bullet.Parent = workspace

	local Origin = CurrentGun:FindFirstChild("FirePoint",true).WorldPosition
	local Parameters = RaycastParams.new()
	Parameters.FilterType = Enum.RaycastFilterType.Exclude
	local Blacklist = {Player.Character}
	for _,v in workspace:GetChildren() do
		
		if v:IsA("BasePart") and v.Name == "Bullet" then
			
			table.insert(Blacklist,v)
			
		end
		
	end
	
	Parameters.FilterDescendantsInstances = Blacklist
	
	local Destination = Mouse.Hit.Position
	
	local Start = CurrentGun:FindFirstChild("FirePoint",true).WorldPosition
	
	local Conversion = 196.2/9.8
	
	local VectorForce = (Destination - Start).Unit * 50 * Conversion
	
	local Acceleration = Vector3.new(0,-9.8,0) * Conversion
	
	Bullet.Position = Start

	task.spawn(function()
		
		while true do
			
			local DeltaTime = RunService.Heartbeat:Wait()
			
			local NextPosition = Vector3.new(
				Bullet.Position.X + VectorForce.X * DeltaTime + 0.5 * Acceleration.X * DeltaTime * DeltaTime,
				Bullet.Position.Y + VectorForce.Y * DeltaTime + 0.5 * Acceleration.Y * DeltaTime * DeltaTime,
				Bullet.Position.Z + VectorForce.Z * DeltaTime + 0.5 * Acceleration.Z * DeltaTime * DeltaTime
			)
			
			Bullet.Position = NextPosition

			
		end
		
	end)

end

It’s anchored,don’t worry.I set it in the code

Alright but the problem is,It’s not easy to handle this since It’s being updated every frame

Here the thing chump, either do a tween or simply apply impluse and roblox do its thing. NGL, most games now use beams instead of actual bullets.

1 Like

I understand,but what I’m doing is already contains beams for visual effect,all I’m doing is,I’m just doing it inside part.
Problem here is It won’t change anything too.Trust me,I have tried everything such as ViewportPointToRay and ScreenPointToRay but none of them worked,so does the Mouse.Hit.Position

The point of using a beam is to avoid using a part for optimization

1 Like

What exactly happens when you run the code??

1 Like

As I said,It starts with offset towards the mouse position when,I’m close towards mouse position and If there’s a mouse target such as a part,It does much more offset towards left and eventually like in the screenshot I have sent,It does this weird offset at the end.

Welp,Any help is still appreciated,would need one.

Have you tried printing the position of the origin and destination after a mouse click?

Edit: oof I just realized it’s a bouncing issue lol

1 Like