Hello, I tried to make it possible to shoot with a button on the phone and I succeeded, but the bullet holes in front of viewmodel. I dont know how to explain, just look at screenshots.
Local script:
while firing == true and equiped and ammo.Value ~= 0 do
if not reloading then
if player.Character.Humanoid.WalkSpeed < 16 then
if player.Character.Humanoid.WalkSpeed <= 8 then
recoilingnmod = 0.8
else
recoilingnmod = 0
end
mouse.TargetFilter = workspace.BulletStorage
mouse.TargetFilter = arms
if ismobile then --checks if player using phone
script.Parent.StartFire:FireServer(workspace.CurrentCamera.CFrame.LookVector * 10000,arms.Model.Handle.GunFirePoint.WorldPosition,recoilingnmod)
else
script.Parent.StartFire:FireServer(mouse.Hit.p,arms.Model.Handle.GunFirePoint.WorldPosition,recoilingnmod)
end
player.PlayerScripts.VisualShot.VFireEvent:Fire(arms)
end
end
task.wait(0.1)
end
And server script(How bullet works)
function NewBullet(ViewmodelHandle)
local bullet = Instance.new("Part")
bullet.Position = ViewmodelHandle
bullet.CanCollide = false
bullet.Transparency = 1
bullet.Size = Vector3.new(0.5,0.5,0.5)
bullet.Name = "bullet"
bullet.Parent = workspace.BulletStorage
bullet:SetNetworkOwner(nil)
return bullet
end
function applyPhysics(bullet,mousePos,recoilmod)
local muzzlevel = 1000
local direction = CFrame.new(bullet.Position,mousePos)
local verticalspread = 1.5 - recoilmod
local horizontalspread = 1.5 - recoilmod
local rng = Random.new()
verticalspread = rng:NextNumber(-verticalspread,verticalspread)
horizontalspread = rng:NextNumber(-horizontalspread,horizontalspread)
verticalspread = math.rad(verticalspread)
horizontalspread = math.rad(horizontalspread)
direction = direction*CFrame.Angles(verticalspread,horizontalspread,0)
direction = direction.LookVector
local mass = bullet:GetMass()
bullet:ApplyImpulse(direction * mass * muzzlevel)
end
Little bit of explanation: When i shoot bullet starts from Viewmodel’s firePoint(attachment), then it’s moves to mousepos, but on mobile i think it’s just moves straight.
Some ideas?