Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Does mouse.Hit.Position work on mobile?

Asked by 3 years ago

If it doesnt how can I make it so whatever direction the player faces it shoots from the angle from the players right hand? I'm pretty basic in scripting i made this after like 30 minutes or an hour of the dev forum and youtube tutorials

The script (local):

local UIS = game:GetService("UserInputService")
local mouse = game.Players.LocalPlayer:GetMouse()
local debounce = false
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

--Animation
local animInstance = Instance.new("Animation")
animInstance.AnimationId = "rbxassetid://04160584403"
local fireballAnim = humanoid:LoadAnimation(animInstance)


local function shootFireball(caster, mousePos)
    if caster == player then
        game.ReplicatedStorage.Events.FireBall:FireServer("Replicate",mousePos) --Show fireball for other players
    end

    local effects = game.ReplicatedStorage.FireBallEffects
    local fireBall = effects.FireBall:Clone()
    local explosion = effects.Explosion:Clone()
    local character = caster.Character

    --Fireball
    fireBall.Position = character.RightHand.Position
    fireBall.Parent = workspace
    fireBall.Sound:Play()
    local weld = Instance.new("WeldConstraint", fireBall)
    weld.Part0 = fireBall
    weld.Part1 = character.RightHand
    wait(0.45)
    weld:Destroy()
    local velocity = Instance.new("BodyVelocity", fireBall)
    velocity.Velocity = CFrame.new(fireBall.Position, mousePos).LookVector * 100

    --Explosion
    fireBall.Touched:Connect(function(hit)
        if hit:IsDescendantOf(character) or hit:FindFirstChild("ParticleEmitter") then return end
        explosion.Position = fireBall.Position
        fireBall:Destroy()
        explosion.Parent = workspace
        explosion.Sound:Play()
        if caster == player then --Make sure the damage doesnt activate when someone else casted
            game.ReplicatedStorage.Events.FireBall:FireServer(hit)
        end
        wait(1)
        explosion:Destroy()
    end)
end

--PC
UIS.InputBegan:Connect(function(key, processed)
    if processed or debounce then return end
    debounce = true

    if key.UserInputType == Enum.UserInputType.Keyboard then
        if key.KeyCode == Enum.KeyCode.One then
            fireballAnim:Play()
            wait(0.75)
            shootFireball(player, mouse.Hit.Position)
        end
    end
    wait(1)
    debounce = false
end)

--Mobile
function onKeyPress(actionName, userInputState, inputObject, position, processed)
    if processed or debounce then return end
        debounce = true
        fireballAnim:Play()
    shootFireball(player, mouse.Hit.Position)
    print("1 was pressed")
        wait(1)
        debounce = false
end
game.ContextActionService:BindAction("keyPressSpecialName", onKeyPress, true, Enum.KeyCode.C)
game.ContextActionService:SetPosition("keyPressSpecialName", UDim2.new(.5,0,-.5,0))
game.ContextActionService:SetImage("keyPressSpecialName", "rbxassetid://73737626")


game.ReplicatedStorage.Events.FireBall.OnClientEvent:Connect(function(caster, mousePos)
    if caster == player then return end --The person casting the fireball can already see it
    shootFireball(caster, mousePos) --Create the fireball
end)
0
look at lines 67-85 Radiant_Sparkles 69 — 3y

1 answer

Log in to vote
1
Answered by
Ashedee 43
3 years ago
Edited 3 years ago

Please search for you answer before posting to reduce duplicated posts.

brycee_o Programmer Feb '18

Works the same on both platforms, mouse position(X,Y) & mouse.Hit work as well

https://devforum.roblox.com/t/how-do-i-get-mouse-hit-p-on-touch-devices/96939/

0
thanks, sorry Radiant_Sparkles 69 — 3y
0
but it says its blocked Radiant_Sparkles 69 — 3y
0
wait nvm Radiant_Sparkles 69 — 3y
Ad

Answer this question