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
5 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:

01script.Parent.OnServerEvent:connect(function(player, mouse)
02    if game.Players[player.Name].Character.HumanoidRootPart:FindFirstChild("AimerGyro") then
03        print("aiming")
04        local gryo = game.Players[player.Name].Character.HumanoidRootPart:FindFirstChild("AimerGyro")
05        gryo.CFrame = mouse
06    else
07        print("making")
08        local g = Instance.new("BodyGyro")
09        g.Name = "AimerGyro"
10        g.Parent = game.Players[player.Name].Character.HumanoidRootPart
11    end
12end)

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

And here is that client script:

01local uis = game:GetService("UserInputService")
02local equipped = false
03local attacking = false
04local debounce = false
05local debounce2 = false
06local mouse = game.Players.LocalPlayer:GetMouse()
07 
08script.Parent.Equipped:connect(function()
09    equipped = true
10end)
11 
12script.Parent.Unequipped:connect(function()
13    equipped = false
14end)
15 
View all 54 lines...
1
CFrame.new(Vector3) LMAOOO Fifkee 2017 — 5y

1 answer

Log in to vote
1
Answered by
Nogalo 148
5 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

1gyro.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 — 5y
Ad

Answer this question