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

Help with a shockwave?

Asked by 9 years ago

I need help with this shockwave script, if two shockwaves overlap, instead of going through each other, they climb over each other. Any ways to combat this?

wait(2)
script.Parent.Transparency = 0
for i = 1, 300 do
script.Parent.CFrame=script.Parent.CFrame*CFrame.new(0,0,0.1)
script.Parent.Size = script.Parent.Size + Vector3.new(0.2,0,0)
wait(0)
end
script.Parent:Destroy()
0
Anchor the parts? YellowoTide 1992 — 9y
0
that doesnt work.. :( connor12260311 383 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago

Try storing the position, changing the size then set the cframe to that position

wait(2)
script.Parent.Transparency = 0

for i = 1, 300 do
    local cf = script.Parent.CFrame*CFrame.new(0,0,0.1)
    script.Parent.Size = script.Parent.Size + Vector3.new(0.2,0,0)
    script.Parent.CFrame=cf
    wait(0)
end

script.Parent:Destroy()
Ad
Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

The problem here is that when you change the .Size of a part, if it overlaps with anything, it will move on top to make room.

You can set .CFrame to combat this behavior -- but you have to know where it was before the problematic shifting around from changing the Size.


Depending on the context, it can be better to make changes relative to where you are now (like you do in line 4), but it is often cleaner to be relative to where you started:

local home = script.Parent.CFrame
local size = script.Parent.Size
for i = 1, 300 do
    script.Parent.CFrame = home * CFrame.new(0, 0, 0.1 * i)
    script.Parent.Size = size + Vector3.new(0.2 * i, 0, 0)
    wait()
end
script.Parent:Destroy()

Also keep in mind that the amount of time wait will pause for is variable, and it can be good practice to actually use the time that has elapsed.

A loop written like this (not relative to where it was in the previous step) is a lot easier to transform into that, since you can just replace i with the time elapsed times some factor:

local started = tick()
repeat
    local elapsed = tick() - started
    local i = elapsed * 30
    script.Parent.CFrame = home * CFrame.new(0, 0, 0.1 * i)
    script.Parent.Size = size + Vector3.new(0.2 * i, 0, 0)
    wait()
until elapsed > 10
script.Parent:Destroy()

Answer this question