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

How to use mouse.hit.LookVector as a CFrame? (for a stone attack)

Asked by
Gojinhan 353 Moderation Voter
4 years ago

Hi, I'm scripting a stone attack for my magic ffa game, I'm good at this sorta thing but you could search the entire planet and still not find a scripter my level who's as awful at CFrame as me.

So, I was wondering. How would I turn a vector3 into a CFrame?

Here's a server script that handles the attack thing:

script.Parent.OnServerEvent:connect(function(player, mouse)
    if game.Players[player.Name].Character.HumanoidRootPart:FindFirstChild("AimerGyro") then
        print("aiming")
        local gryo = game.Players[player.Name].Character.HumanoidRootPart:FindFirstChild("AimerGyro")
        gryo.CFrame = mouse
    else
        print("making")
        local g = Instance.new("BodyGyro")
        g.Name = "AimerGyro"
        g.Parent = game.Players[player.Name].Character.HumanoidRootPart
    end
end)

To clarify, that mouse variable is mouse.hit sent over from the client.

And here is that client script:

local uis = game:GetService("UserInputService")
local equipped = false
local attacking = false
local debounce = false
local debounce2 = false
local mouse = game.Players.LocalPlayer:GetMouse()

script.Parent.Equipped:connect(function()
    equipped = true
end)

script.Parent.Unequipped:connect(function()
    equipped = false
end)

uis.InputBegan:connect(function(input, gp)
    if gp then
        return
    else
        if input.KeyCode == Enum.KeyCode.Q and not attacking and not debounce then
            attacking = true
            debounce = true

            while attacking do
                if attacking then
                    script.Parent.StoneQ:FireServer(mouse.hit)
                else
                    break
                end
                wait(0.1)
            end
            -- charge
            print("charging")
            wait(4)
            debounce = false
        end
    end
end)

uis.InputEnded:connect(function(input, gp)
    if gp then
        return
    else
        if input.KeyCode == Enum.KeyCode.Q and attacking and not debounce2 then
            attacking = false
            debounce2 = true

            -- release
            print("released")
            wait(4)
            debounce2 = false
        end
    end
end)
1
CFrame.new(Vector3) LMAOOO Fifkee 2017 — 4y

1 answer

Log in to vote
1
Answered by
Nogalo 148
4 years ago

your script is quite messy but from what i understand you're trying to aim the projectile where the mouse is aiming

in this case this you create a new cframe like this

gyro.CFrame = CFrame.new(gyro.CFrame.p, mouse)

CFrame is composed of 2 vectors, 1 for position of the part and 1 for it's rotation

CFrame.p turns the CFrame into a vector3 by only taking it's position values, the second vector is mouse.hit

by combining them you get a new CFrame

1
thank Gojinhan 353 — 4y
Ad

Answer this question