การสร้างเงื่อนไข if condition

 เราสามารถระบุเงื่อนไขในการทำงาน เช่น ถ้าตำแหน่งของลูกบอลไปตกกระทบกำแพง ให้เปลี่ยนทิศทางของตำแหน่งเป็นด้านตรงข้าม




local velocity = Vector3.new(1, 0, 2)
local part = Vector3.new(0, 0, 0)
local box = Vector3.new(10, 0, 10) -- from origin

while true do -- Infinite Loop

part = part + velocity

print(part)

-- Update Velocity
if part.X > wall.X or part.X <0 then
velocity.X = velocity.X * -1
end

if part.Z > wall.Z or part.Z <0 then
velocity.Z = velocity.Z * -1
end

task.wait(1)

end

ความคิดเห็น