[help] Projectile System Mobile

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?

  1. 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! :+1:

image

You need to minus off GuiInset for Y! This is because TopbarUI exists.

The GUI? If that, it does the same thing.

workspace.CurrentCamera.ViewportSize.X / 2, workspace.CurrentCamera.ViewportSize.Y / 2 - (game:GetService("GuiService"):GetGuiInset().Y/2))

You need to add the following for the Y.

Oh alright I didn’t know that but to try. Hold on!


It does this

Camera:ViewportPointToRay(ViewportSize.X / 2, ViewportSize.Y / 2 - (GuiService:GetGuiInset().Y/2))

Try camera:ScreenPointToRay()

1 Like

image
It reduced, It might need some reduce on X or Y?

Hmm, does :GetSpread() change where the ray starts/ends?

It expectedly does do random, but i’ll try disabling that,

(workspace.CurrentCamera.ViewportSize.X / 2 - (game:GetService("GuiService"):GetGuiInset().X/2), workspace.CurrentCamera.ViewportSize.Y / 2 - (game:GetService("GuiService"):GetGuiInset().Y/2))

Since your X is off, maybe try subtracting from X as well.

It does do the same, I got to go now. I’ll message whenever I online. Thanks for trying.

Ill try that