airutils/water_splash.lua

53 lines
1.5 KiB
Lua
Raw Normal View History

2024-08-19 20:44:22 -03:00
local function calculateVelocity(magnitude, angle)
-- Calcula os componentes do vetor usando ângulo polar
-- Supondo que o ângulo é dado no plano XY, com z = 0
local velocity = {
x = magnitude * math.cos(angle),
y = 0, -- Se a velocidade não tem componente z
z = magnitude * math.sin(angle),
}
2024-08-19 20:44:22 -03:00
return velocity
end
2024-08-21 20:27:59 -03:00
local function water_particle(pos, accell)
2024-08-19 20:44:22 -03:00
if airutils.splash_texture == nil then return end
if airutils.splash_texture == "" then return end
minetest.add_particle({
pos = pos,
2024-08-21 20:27:59 -03:00
velocity = {x = 0, y = 0, z = 0},
acceleration = accell, --{x = 0, y = 0, z = 0},
2024-08-19 20:44:22 -03:00
expirationtime = 2.0,
size = 4.8,
collisiondetection = false,
collision_removal = false,
vertical = false,
texture = airutils.splash_texture,
})
end
function airutils.add_splash(pos, yaw, x_pos)
local direction = yaw
local spl_pos = vector.new(pos)
--water_particle(spl_pos, {x=0,y=0,z=0})
2024-08-19 20:44:22 -03:00
--right
local move = x_pos/10
spl_pos.x = spl_pos.x + move * math.cos(direction)
spl_pos.z = spl_pos.z + move * math.sin(direction)
2024-08-21 20:27:59 -03:00
local velocity = calculateVelocity(0.2, yaw)
2024-08-19 20:44:22 -03:00
water_particle(spl_pos, velocity)
--left
direction = direction - math.rad(180)
spl_pos = vector.new(pos)
spl_pos.x = spl_pos.x + move * math.cos(direction)
spl_pos.z = spl_pos.z + move * math.sin(direction)
2024-08-21 20:27:59 -03:00
velocity = calculateVelocity(0.2, yaw - math.rad(180))
2024-08-19 20:44:22 -03:00
water_particle(spl_pos, velocity)
end