added camera rotation by player axis

master
Alexsandro Percy 2021-03-27 19:42:28 -03:00
parent 230aba803a
commit eeb0cb8d87
3 changed files with 67 additions and 18 deletions

View File

@ -1,8 +1,8 @@
--global constants
helicopter.gravity = tonumber(minetest.settings:get("movement_gravity")) or 9.8
helicopter.tilting_speed = 1
helicopter.tilting_max = 0.35
helicopter.tilting_speed = 0.3
helicopter.tilting_max = 0.15
helicopter.power_max = 15
helicopter.power_min = 0.2 -- if negative, the helicopter can actively fly downwards
helicopter.wanted_vert_speed = 10
@ -55,7 +55,7 @@ function helicopter.heli_control(self, dtime, touching_ground, liquid_below, vel
if ctrl.jump then
vert_vel_goal = vert_vel_goal + helicopter.wanted_vert_speed
end
if ctrl.sneak then
if ctrl.aux1 then
vert_vel_goal = vert_vel_goal - helicopter.wanted_vert_speed
end
else
@ -64,6 +64,8 @@ function helicopter.heli_control(self, dtime, touching_ground, liquid_below, vel
-- rotation
if not touching_ground then
local rotation = self.object:get_rotation()
local yaw = rotation.y
local tilting_goal = vector.new()
if ctrl.up then
tilting_goal.z = tilting_goal.z + 1
@ -71,12 +73,23 @@ function helicopter.heli_control(self, dtime, touching_ground, liquid_below, vel
if ctrl.down then
tilting_goal.z = tilting_goal.z - 1
end
if ctrl.right then
tilting_goal.x = tilting_goal.x + 1
end
if ctrl.left then
tilting_goal.x = tilting_goal.x - 1
end
if ctrl.sneak then
if ctrl.right then
tilting_goal.x = tilting_goal.x + 1
end
if ctrl.left then
tilting_goal.x = tilting_goal.x - 1
end
else
if ctrl.right then
yaw = yaw - 0.02
tilting_goal.x = tilting_goal.x + 0.2
end
if ctrl.left then
yaw = yaw + 0.02
tilting_goal.x = tilting_goal.x - 0.2
end
end
tilting_goal = vector.multiply(vector.normalize(tilting_goal), helicopter.tilting_max)
-- tilting
@ -101,7 +114,9 @@ function helicopter.heli_control(self, dtime, touching_ground, liquid_below, vel
)
rot = matrix3.to_pitch_yaw_roll(rot_mat)
rot.y = driver:get_look_horizontal()
--rot.y = driver:get_look_horizontal()
rot.y = yaw
else
rot.x = 0

View File

@ -89,8 +89,8 @@ function helicopter.attach(self, player)
self.object:set_animation_frame_speed(30)
-- attach the driver
player:set_attach(self.object, "", {x = 4.2, y = 10.5, z = 2}, {x = 0, y = 0, z = 0})
player:set_eye_offset({x = 4.2, y = 7, z = 2}, {x = 0, y = 8, z = -5})
player:set_attach(self.pilot_seat_base, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
player:set_eye_offset({x = 0, y = -3, z = 3}, {x = 0, y = 8, z = -5})
player_api.player_attached[name] = true
-- make the driver sit
minetest.after(0.2, function()
@ -134,8 +134,8 @@ function helicopter.attach_pax(self, player)
local name = player:get_player_name()
self._passenger = name
-- attach the passenger
player:set_attach(self.object, "", {x = -4.2, y = 10.5, z = 2}, {x = 0, y = 0, z = 0})
player:set_eye_offset({x = -4.2, y = 7, z = 3}, {x = 0, y = 8, z = -5})
player:set_attach(self.passenger_seat_base, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
player:set_eye_offset({x = 0, y = -3, z = 3}, {x = 0, y = 8, z = -5})
player_api.player_attached[name] = true
-- make the driver sit
minetest.after(0.2, function()
@ -210,6 +210,28 @@ end
-- entity
--
minetest.register_entity('helicopter:seat_base',{
initial_properties = {
physical = false,
collide_with_objects=false,
pointable=false,
visual = "mesh",
mesh = "seat_base.b3d",
textures = {"helicopter_black.png",},
},
on_activate = function(self,std)
self.sdata = minetest.deserialize(std) or {}
if self.sdata.remove then self.object:remove() end
end,
get_staticdata=function(self)
self.sdata.remove=true
return minetest.serialize(self.sdata)
end,
})
minetest.register_entity("helicopter:heli", {
initial_properties = {
physical = true,
@ -268,6 +290,14 @@ minetest.register_entity("helicopter:heli", {
pointer:set_attach(self.object,'',{x=0,y=11.26,z=9.37},{x=0,y=0,z=energy_indicator_angle})
self.pointer = pointer
local pilot_seat_base=minetest.add_entity(pos,'helicopter:seat_base')
pilot_seat_base:set_attach(self.object,'',{x=4.2,y=10,z=2},{x=0,y=0,z=0})
self.pilot_seat_base = pilot_seat_base
local passenger_seat_base=minetest.add_entity(pos,'helicopter:seat_base')
passenger_seat_base:set_attach(self.object,'',{x=-4.2,y=10,z=2},{x=0,y=0,z=0})
self.passenger_seat_base = passenger_seat_base
-- set the animation once and later only change the speed
self.object:set_animation({x = 0, y = 11}, 0, 0, true)
@ -326,7 +356,9 @@ minetest.register_entity("helicopter:heli", {
if player then
local player_attach = player:get_attach()
if player_attach then
if player_attach == self.object then is_attached = true end
--XXXXXXXX
if player_attach == self.pilot_seat_base then is_attached = true end
--XXXXXXXX
end
end
end
@ -402,8 +434,10 @@ minetest.register_entity("helicopter:heli", {
local touching_ground, liquid_below = helicopter.check_node_below(self.object)
--XXXXXXXX
local is_attached = false
if puncher:get_attach() == self.object then is_attached = true end
if puncher:get_attach() == self.pilot_seat_base then is_attached = true end
--XXXXXXXX
local itmstck=puncher:get_wielded_item()
local item_name = ""
@ -487,11 +521,11 @@ minetest.register_entity("helicopter:heli", {
if self._passenger == nil then
helicopter.attach_pax(self, clicker)
else
helicopter.detach_pax(self, clicker)
helicopter.dettach_pax(self, clicker)
end
else
if self._passenger then
helicopter.detach_pax(self, clicker)
helicopter.dettach_pax(self, clicker)
end
end
end

BIN
models/seat_base.b3d Executable file

Binary file not shown.