Update entities.lua

improvement of wind effects
This commit is contained in:
Alexsandro Percy 2023-03-27 14:32:14 -03:00 committed by GitHub
parent 02ea642680
commit 358153c95a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -595,11 +595,15 @@ minetest.register_entity("ap_airship:airship", {
local hull_direction = minetest.yaw_to_dir(yaw) local hull_direction = minetest.yaw_to_dir(yaw)
local nhdir = {x=hull_direction.z,y=0,z=-hull_direction.x} -- lateral unit vector local nhdir = {x=hull_direction.z,y=0,z=-hull_direction.x} -- lateral unit vector
local velocity = self.object:get_velocity() local velocity = self.object:get_velocity()
local wind_speed = airutils.get_wind(curr_pos, 0.15)
local longit_speed = ap_airship.dot(velocity,hull_direction) local longit_speed = ap_airship.dot(velocity,hull_direction)
self._longit_speed = longit_speed --for anchor verify self._longit_speed = longit_speed --for anchor verify
local longit_drag = vector.multiply(hull_direction,longit_speed* local relative_longit_speed = ap_airship.dot(vector.add(velocity, wind_speed), hull_direction)
longit_speed*LONGIT_DRAG_FACTOR*-1*ap_airship.sign(longit_speed))
local longit_drag = vector.multiply(hull_direction,relative_longit_speed*
relative_longit_speed*LONGIT_DRAG_FACTOR*-1*ap_airship.sign(relative_longit_speed))
local later_speed = ap_airship.dot(velocity,nhdir) local later_speed = ap_airship.dot(velocity,nhdir)
local later_drag = vector.multiply(nhdir,later_speed*later_speed* local later_drag = vector.multiply(nhdir,later_speed*later_speed*
LATER_DRAG_FACTOR*-1*ap_airship.sign(later_speed)) LATER_DRAG_FACTOR*-1*ap_airship.sign(later_speed))
@ -626,7 +630,7 @@ minetest.register_entity("ap_airship:airship", {
end end
if self.owner == "" then return end if self.owner == "" then return end
--[[if longit_speed == 0 and is_flying == false and is_attached == false and self._engine_running == false then --[[if relative_longit_speed == 0 and is_flying == false and is_attached == false and self._engine_running == false then
self.object:move_to(curr_pos) self.object:move_to(curr_pos)
--self.object:set_acceleration({x=0,y=airutils.gravity,z=0}) --self.object:set_acceleration({x=0,y=airutils.gravity,z=0})
return return
@ -635,14 +639,14 @@ minetest.register_entity("ap_airship:airship", {
--detect collision --detect collision
ap_airship.testDamage(self, vel, curr_pos) ap_airship.testDamage(self, vel, curr_pos)
accel = ap_airship.control(self, self.dtime, hull_direction, longit_speed, accel) or vel accel = ap_airship.control(self, self.dtime, hull_direction, relative_longit_speed, accel) or vel
--get disconnected players --get disconnected players
ap_airship.rescueConnectionFailedPassengers(self) ap_airship.rescueConnectionFailedPassengers(self)
local turn_rate = math.rad(9) local turn_rate = math.rad(9)
newyaw = yaw + self.dtime*(1 - 1 / (math.abs(longit_speed) + 1)) * newyaw = yaw + self.dtime*(1 - 1 / (math.abs(relative_longit_speed) + 1)) *
self._rudder_angle / 30 * turn_rate * ap_airship.sign(longit_speed) self._rudder_angle / 30 * turn_rate * ap_airship.sign(relative_longit_speed)
ap_airship.engine_step(self, accel) ap_airship.engine_step(self, accel)
@ -655,7 +659,7 @@ minetest.register_entity("ap_airship:airship", {
local newroll = 0 local newroll = 0
if self._last_roll ~= nil then newroll = self._last_roll end if self._last_roll ~= nil then newroll = self._last_roll end
--oscilation when stoped --oscilation when stoped
if longit_speed == 0 then if relative_longit_speed == 0 then
local time_correction = (self.dtime/ap_airship.ideal_step) local time_correction = (self.dtime/ap_airship.ideal_step)
--stoped --stoped
if self._roll_state == nil then if self._roll_state == nil then
@ -680,18 +684,18 @@ minetest.register_entity("ap_airship:airship", {
--minetest.chat_send_all('newroll: '.. newroll) --minetest.chat_send_all('newroll: '.. newroll)
--------------------------------- ---------------------------------
-- end roll -- end roll
local wind = airutils.get_wind(curr_pos, 0.15)
local wind_yaw = minetest.dir_to_yaw(wind) local wind_yaw = minetest.dir_to_yaw(wind_speed)
--minetest.chat_send_all("x: "..wind.x.. " - z: "..wind.z.." - yaw: "..math.deg(wind_yaw).. " - orig: "..wind_yaw) --minetest.chat_send_all("x: "..wind_speed.x.. " - z: "..wind_speed.z.." - yaw: "..math.deg(wind_yaw).. " - orig: "..wind_yaw)
if self.anchored == false and self.isonground == false then if self.anchored == false and self.isonground == false then
accel = vector.add(accel, wind) accel = vector.add(accel, wind_speed)
else else
accel = vector.new() accel = vector.new()
end end
accel.y = accel_y accel.y = accel_y
newpitch = velocity.y * math.rad(1.5) * (longit_speed/3) newpitch = velocity.y * math.rad(1.5) * (relative_longit_speed/3)
local noded = airutils.nodeatpos(airutils.pos_shift(curr_pos,{y=-4.5})) local noded = airutils.nodeatpos(airutils.pos_shift(curr_pos,{y=-4.5}))
if (noded and noded.drawtype ~= 'airlike') or self.isonground then if (noded and noded.drawtype ~= 'airlike') or self.isonground then