I need anyone help for this Projectile System that supports Mobile.
1. What’s the Issue?
The Mobile shoots in other way than pointing in cursor.
2. Any Solutions You Tried?
- Make Camera Casts then the direction will be the pointer. (CURRENT)
Thats only I tried.
3. Code and Video?
CODE
Gui Module
local Module = {}
local GUI = script.Parent
local Cursor = GUI:WaitForChild('Cursor')
function Module.UpdateCursorPos(mousePos: UDim2, isMobile: boolean, viewportSize)
if isMobile then
Cursor.Position = UDim2.fromOffset(viewportSize.X/2,viewportSize.Y/2)
return
end
Cursor.Position = mousePos
end
return Module
Cast Function
if InMobile then
-- Camera Point Ray
local ViewportSize = Camera.ViewportSize
local ViewportRay = Camera:ViewportPointToRay(ViewportSize.X/2,ViewportSize.Y/2)
-- Ray
CalculatedRay = Ray.new(FirePoint.WorldPosition, GetSpread()*(ViewportRay.Direction.Unit*MaxDistance))
local InstanceHit: Instance, Position: Vector3 = Cast:Cast(
BulletType,
LocalRemotes,
Sounds,
Weapon,
Speed,
MaxDistance,
FirePoint,
Mouse,
CalculatedRay,
IgnoredInstances,
Random,
Rad,
Dimension,
Thickness,
Lifetime,
Debris,
IgnoredContainer,
LocalUser,
Remotes,
OutlineEnabled
)
if BulletType == 'CLASSIC' then
LocalRemotes.VerifyHit:FireServer(Position, InstanceHit, Sounds.FireSound)
end
end
I appreciate for help!