-
What do you want to achieve?
I want to have a bullet which will follow the Ray which is casted by the gun and also have a drop like Phantom Forces or other cool FPS games in Roblox. -
What is the issue?
As I am new to the subject of Raycasting, I can’t figure out a way to do this. -
What solutions have you tried so far? I tried to find some solutions on the Dev forum, but I couldn’t understand much from that
Currently, I am using EgoMoose’s FPS Framework and I suppose I will have to make changes in the fire event, so theres the code for it.
function fps:fire()
if (self.isEquipped and self.isAlive) and self.weapon.CurrentAmmo.Value > 0 then
local from = self.isAiming and self.weapon.Aim or self.weapon.Shoot;
local ray = Ray.new(from.Position, from.CFrame.lookVector*500);
local hit, pos, normal = game.Workspace:FindPartOnRayWithIgnoreList(ray, {self.humanoid.Parent, self.weapon});
self.weapon.Shoot.Flash.Enabled = true
self.weapon.Shoot.Smoke.Enabled = true
wait(.25)
self.weapon.Shoot.Flash.Enabled = false
self.weapon.Shoot.Smoke.Enabled = false
self.weapon.CurrentAmmo.Value = self.weapon.CurrentAmmo.Value - 1
local GunUI = game.Players.LocalPlayer.PlayerGui.GunUI.Info
GunUI.Ammo.Text = self.weapon.CurrentAmmo.Value.."/"..self.weapon.MaxAmmo.Value
local enemyHum;
if (hit) then
local players = game.Players:GetPlayers();
for i = 1, #players do
if (players[i].Character and hit:IsDescendantOf(players[i].Character)) then
enemyHum = players[i].Character:FindFirstChild("Humanoid");
break;
end
end
if (enemyHum) then
enemyHum:TakeDamage(self.settings.damageFunc())
end
end
self.recoil.p = self.settings.recoilFunc();
remotes.fire:FireServer(self.Right, self.Left, enemyHum);
local serverWeapon = self.humanoid.Parent:FindFirstChild(self.weapon.Name)
local fireSound = serverWeapon.Handle:FindFirstChild("Fire");
if (fireSound) then
fireSound:Play();
end
end
end