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

How to change the size of only 1 surface of a part ?

Asked by 6 years ago
Edited 6 years ago

I've added in my game a script. When we press the correct key it is supposed to create a beam in front of you that deals damage but there is a problem : I dont know how to change the size of only 1 surface of a part , without using Resize() caus it doesnt work with .Touched event. I tried using Vector3 but im not totally at ease with it. I found how to increase the size properly but the size does not increase in front. For example, if i chose to increase the Front size with Vector3, it also increase Back size. I though about modifying the position but i dont know how to do it.

So, i know that wasnt very simple to understand so, this is what is would like : When it grow (by the loop in the code down below) i would like the beam to always be at the correct position (the beginning just at my wand's position and the end at where i aimed the mouse)

Here is the code :

game:GetService("ReplicatedStorage").Tool.OnServerEvent:connect(function(player, position)
    -- the position variable is the position where the player clicked with the mouse
    local tool = game.Workspace[player.Name].WandTool

    local beam = script.Parent
    beam.CFrame = CFrame.new(tool.Emitter.CFrame.p, position)

    for i = 1,20 do
    beam.Size = beam.Size + Vector3.new(0,0,1) --This increase the size of both side (Front and Back, Top and Bottom, etc.... it depends of what side i chose to modify)
    beam.Position = beam.Position + Vector3.new(0,0,1) -- It doesnt do the right thing
    wait(0.1)
    end
end)

1 answer

Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
6 years ago

Make a mental image of what happens. A direct resize changes two sides equally; each side extends by half the resize. To get the opposite side to its original position, you should use half the resize again, not the whole.

so this is probably all you need to change ye?

beam.Position = beam.Position + Vector3.new(0,0,0.5)
0
When im using this method, the beam always go in the same direction, even if i move NotZuraax 68 — 6y
0
Zurax, yes, but that's not the question you asked. You wanted to offset correctly. I fixed it. cabbler 1942 — 6y
0
I know, that's why i changed the question (not the whole question but just a little bit, to indicate what i realy want, because i know im often misunderstood)) NotZuraax 68 — 6y
Ad

Answer this question