4 -- By webdesigner97(No license?)
5 -- Tweaked by Kaadmy, for Pixture
8 function air_physics(v
)
9 local m
= 80 -- Weight of player, kg
10 local g
= -9.81 -- Earth Acceleration, m/s^2
11 local cw
= 1.25 -- Drag coefficient
12 local rho
= 1.2 -- Density of air (on ground, not accurate), kg/m^3
13 local A
= 25 -- Surface of the parachute, m^2
15 return ((m
* g
+ 0.5 * cw
* rho
* A
* v
* v
) / m
)
18 minetest
.register_craftitem(
19 "parachute:parachute", {
20 description
= "Parachute",
21 inventory_image
= "parachute_inventory.png",
22 wield_image
= "parachute_inventory.png",
24 on_use
= function(itemstack
, player
, pointed_thing
)
25 local name
= player
:get_player_name()
27 local pos
= player
:getpos()
29 local on
= minetest
.get_node({x
= pos
.x
, y
= pos
.y
- 1, z
= pos
.z
})
31 if default
.player_attached
[name
] then
35 if on
.name
== "air" then
39 local ent
= minetest
.add_entity(pos
, "parachute:entity")
44 y
= math
.min(0, player
:get_player_velocity().y
),
48 player
:set_attach(ent
, "", {x
= 0, y
= -8, z
= 0}, {x
= 0, y
= 0, z
= 0})
50 ent
:setyaw(player
:get_look_horizontal())
52 ent
= ent
:get_luaentity()
55 default
.player_attached
[player
:get_player_name()] = true
61 minetest
.chat_send_player(
62 player
:get_player_name(),
63 "Cannot open parachute on ground!")
68 minetest
.register_entity(
72 mesh
= "parachute.b3d",
73 textures
= {"parachute_mesh.png"},
74 collisionbox
= {0, 0, 0, 0, 0, 0},
75 automatic_face_movement_dir
= -90,
77 on_step
= function(self
, dtime
)
78 local pos
= self
.object
:getpos()
79 local under
= minetest
.get_node({x
= pos
.x
, y
= pos
.y
- 1, z
= pos
.z
})
81 if self
.attached
~= nil then
82 local player
= minetest
.get_player_by_name(self
.attached
)
84 local vel
= self
.object
:getvelocity()
86 local accel
= {x
= 0, y
= 0, z
= 0}
88 local lookyaw
= math
.pi
- player
:get_look_horizontal()
91 lookyaw
= lookyaw
+ (math
.pi
* 2)
94 if lookyaw
>= (math
.pi
* 2) then
95 lookyaw
= lookyaw
- (math
.pi
* 2)
97 -- self.object:setyaw(lookyaw)
99 local s
= math
.sin(lookyaw
)
100 local c
= math
.cos(lookyaw
)
102 local sr
= math
.sin(lookyaw
- (math
.pi
/ 2))
103 local cr
= math
.cos(lookyaw
- (math
.pi
/ 2))
105 local controls
= player
:get_player_control()
109 if controls
.down
then
112 elseif controls
.up
then
117 if controls
.right
then
120 elseif controls
.left
then
121 accel
.x
= sr
* -speed
122 accel
.z
= cr
* -speed
125 accel
.y
= accel
.y
+ air_physics(vel
.y
) * 0.25
127 self
.object
:setacceleration(accel
)
129 if under
.name
~= "air" then
130 default
.player_attached
[self
.attached
] = false
134 if under
.name
~= "air" then
135 if self
.attached
~= nil then
136 default
.player_attached
[self
.attached
] = false
138 self
.object
:set_detach()
148 crafting
.register_craft(
150 output
= "parachute:parachute",
160 achievements
.register_achievement(
164 description
= "Craft 5 parachutes.",
166 craftitem
= "parachute:parachute",
169 default
.log("mod:parachute", "loaded")