How can i make to so my projectile doesnt bug out when i click the sky?
Instead of following mouse.hit i want it to follow the x and z axis .What i mean is if i click straight up my projectile still applies the force it should if i clicked right beside it.
(Im not that great at explaining sry if its confusing)
My code:
local Pistol = script.Parent
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Cooldown = false
local Debris = game:GetService("Debris")
local Bullet = game.ReplicatedStorage.Bullet
local Character = Player.Character
local HRP = Character.HumanoidRootPart
local Sound = Pistol.Sound
local Debris = game:GetService("Debris")
Pistol.Activated:Connect(function()
if Cooldown == false then
Cooldown = true
local Direction = (Mouse.Hit.Position - Pistol.FirePart.Position)
local NewBullet = Bullet:Clone()
NewBullet.Position = Pistol.FirePart.Position
NewBullet.Parent = workspace
local Magnitude = 0.01 + Direction.Magnitude * 0.01
local Duration = Magnitude
local Gravity = workspace.Gravity / 2
local Force = Direction / Duration + Vector3.new(0, Gravity, 0) * Duration
print(Force)
NewBullet:ApplyImpulse(Force * NewBullet.AssemblyMass)
Debris:AddItem(NewBullet, 10)
task.wait()
Cooldown = false
end
end)
It looked like you were clicking the void. (Maybe limit how far out you are able to shoot?) You could use a raycast to ensure a position of how far out you want it to shoot to? (Raycast from your camera to your mouse in the 3d plane? Limit the range using some math, maybe?)
A raycast would work but if i click on the void the raycast would be nil and wouldnt shoot my projectile. I still want it to shoot if click the void. My fix would be making the projectile count the x and z axis of the mouse and the y axis would scale with the x and z coordiantes.
Sorry for the misunderstanding, you actually have to use Mouse.Orientation and get the Position of the orientation and face the projectile to the mouses orientation position.
I shouldve specified what i needed my bad. What i mean is when i click i want the projectile to only follow the x and z axis of the world where the mouse is. And the Y axis already scales because of magnitude. I think ill put an example of what i mean if you dont understand.