- What do you want to achieve? Keep it simple and clear!
Simple, the Ray must shoot straight and that’s it.
- What is the issue? Include screenshots / videos if possible!
In the game, the ray’s end direction is going up (LOOK AT THE MOUSE CURSOR CLOSELY)
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I don’t know. The code are simple.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local function ShootFunction(Player, MouseHit)
if Reloading then
return
end
if Ammo.Value == 0 then
ReloadFunction()
return
else
local rayOrigin = Weapon.Muzzle.CFrame.p
local maxDistance = 2000 -- Maximum distance for straight shooting
local direction = (MouseHit - rayOrigin).Unit
local ray = Ray.new(Weapon.Muzzle.CFrame.p,(MouseHit - Weapon.Muzzle.CFrame.p).Unit * maxDistance)
local ignoreList = { Weapon.Parent, workspace.RayContainer }
local hit, position = workspace:FindPartOnRayWithIgnoreList(ray, ignoreList, false, true)
if hit then
local hum = hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid")
if hum then
hum:TakeDamage(11)
end
end
Ammo.Value -= 1
local Range = (position - Weapon.Muzzle.Position).Magnitude
local Ray = Instance.new("Part")
Ray.Size = Vector3.new(0.2, 0.2, Range)
Ray.CFrame = CFrame.new(position, Weapon.Muzzle.CFrame.p) * CFrame.new(0, 0, -Range / 2)
Ray.Anchored = true
Ray.CanCollide = false
Ray.Parent = workspace.RayContainer
Ray.Color = Color3.fromRGB(255, 255, 127)
Ray.Material = Enum.Material.Neon
FireSound:Play()
local Goal = {}
Goal.Transparency = 1
Goal.Size = Vector3.new(0.05, 0.05, Range)
local TweenInfo = TweenInfo.new(0.2)
local TweenRay = Tween:Create(Ray, TweenInfo, Goal)
TweenRay:Play()
ShootAnim:Play()
Debris:AddItem(Ray, 0.2)
end
end
Ok that’s it. Thanks a lot.