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

How can i create a part that grows in the direction of where your mouse aim ?

Asked by 7 years ago

There is a script that create a beam in front of you when you click with the mouse. Normally, the beam is supposed to grows to where you clicked with the mouse until a certain size (It does not grows over a certains size, for example : 75). Also, only the front part must grows. When you click, the part appears a grows.... from both side (Front and Back) and i dont know how to change the position to make the begining of the beam always starts in front of you and the end finishes to where you click.

I've used Ray and CFrame to define the first position (when you just clicked) but not the position for when it's growing.

I mean :

01local tool = script.Parent
02local ray = Ray.new(tool.Emitter.CFrame.p, (player:GetMouse().Hit.p - tool.Emitter.CFrame.p).unit * 75)
03local part,position = game.Workspace:FindPartOnRay(ray, player.Character, false, false)
04 
05game.ReplicatedStorage.Beam:FireServer(tool, position)
06--this part is from a local script in a tool
07 
08 
09 
10--this part is in a Script in ServerScriptService
11game.ReplicatedStorage.Beam.OnServerEvent:connect(function(player, tool, position)
12    local distance = (tool.Emitter.CFrame.p - position).magnitude
13 
14    for i = 0,distance,6 do
15        beam.CFrame = CFrame.new(tool.Emitter.CFrame.p, position)
View all 23 lines...

Now , all i need is to define the position each time the part grows, but i dont know how to do this. Could someone help me ?

1 answer

Log in to vote
0
Answered by
Vulkarin 581 Moderation Voter
7 years ago

You can move the axis you increased by half of the size increase

1for i = 0,25 do
2    beam.Size = beam.Size + Vector3.new(0,0, 2.96)
3    beam.CFrame = beam.CFrame + Vector3.new(0,0, -2.96/2)
4    wait(0.01)
5end
0
I already tried it and the beam always move to the same direction, not where i clicked NotZuraax 68 — 7y
Ad

Answer this question