mirror of
https://github.com/APercy/automobiles_pck
synced 2025-06-15 13:28:02 +02:00
experiments with scaling
This commit is contained in:
parent
a92bf30b43
commit
2ecb7c6280
@ -112,3 +112,40 @@ if minetest.get_modpath("default") then
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
-- beetle
|
||||
minetest.register_tool("automobiles_beetle:rc_beetle", {
|
||||
description = "R/C Beetle",
|
||||
inventory_image = "automobiles_beetle.png",
|
||||
liquids_pointable = false,
|
||||
stack_max = 1,
|
||||
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
if pointed_thing.type ~= "node" then
|
||||
return
|
||||
end
|
||||
|
||||
local stack_meta = itemstack:get_meta()
|
||||
local staticdata = stack_meta:get_string("staticdata")
|
||||
|
||||
local pointed_pos = pointed_thing.above
|
||||
--pointed_pos.y=pointed_pos.y+0.2
|
||||
local car = minetest.add_entity(pointed_pos, "automobiles_beetle:rc_beetle", staticdata)
|
||||
if car and placer then
|
||||
local ent = car:get_luaentity()
|
||||
local owner = placer:get_player_name()
|
||||
if ent then
|
||||
ent.owner = owner
|
||||
ent.hp = 1 --reset hp
|
||||
--minetest.chat_send_all("owner: " .. ent.owner)
|
||||
car:set_yaw(placer:get_look_horizontal())
|
||||
itemstack:take_item()
|
||||
ent.object:set_acceleration({x=0,y=-automobiles_lib.gravity,z=0})
|
||||
automobiles_lib.setText(ent, S("R/C Beetle"))
|
||||
automobiles_lib.create_inventory(ent, ent._trunk_slots, owner)
|
||||
end
|
||||
end
|
||||
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
@ -493,3 +493,15 @@ auto_beetle.car_properties2._show_rag = true
|
||||
|
||||
minetest.register_entity("automobiles_beetle:beetle_conv", auto_beetle.car_properties2)
|
||||
|
||||
|
||||
auto_beetle.car_properties3 = automobiles_lib.properties_copy(auto_beetle.car_properties1)
|
||||
auto_beetle.car_properties3.initial_properties = automobiles_lib.properties_copy(auto_beetle.car_properties1.initial_properties)
|
||||
auto_beetle.car_properties3._vehicle_scale = 0.1
|
||||
auto_beetle.car_properties3._vehicle_power_scale = 0.12
|
||||
auto_beetle.car_properties3._ground_friction = 0.5
|
||||
auto_beetle.car_properties3.initial_properties.collisionbox = {-0.01, -0.02, -0.01, 0.01, 0.18, 0.01}
|
||||
auto_beetle.car_properties3.initial_properties.selectionbox = {-0.2, 0.0, -0.2, 0.2, 0.2, 0.2}
|
||||
auto_beetle.car_properties3._color = "#992222"
|
||||
|
||||
minetest.register_entity("automobiles_beetle:rc_beetle", auto_beetle.car_properties3)
|
||||
|
||||
|
@ -51,7 +51,11 @@ function automobiles_lib.control(self, dtime, hull_direction, longit_speed, long
|
||||
longit_drag = longit_drag or 0
|
||||
later_drag = later_drag or 0
|
||||
max_acc_factor = max_acc_factor or 0
|
||||
max_acc_factor = max_acc_factor
|
||||
|
||||
max_speed = max_speed or 0
|
||||
max_speed = max_speed
|
||||
|
||||
steering_limit = steering_limit or 0
|
||||
steering_speed = steering_speed or 0
|
||||
|
||||
|
@ -57,6 +57,7 @@ function automobiles_lib.physics(self)
|
||||
new_velocity = {x=new_velocity.x*friction,
|
||||
y=new_velocity.y,
|
||||
z=new_velocity.z*friction}
|
||||
--core.chat_send_all(dump(friction))
|
||||
|
||||
-- bounciness
|
||||
if self.springiness and self.springiness > 0 and self.buoyancy >= 1 then
|
||||
|
@ -189,6 +189,8 @@ function automobiles_lib.get_staticdata(self)
|
||||
stored_inv_id = self._inv_id,
|
||||
stored_car_type = self._car_type,
|
||||
stored_car_gravity = self._car_gravity,
|
||||
stored_scale = self._vehicle_scale or 1,
|
||||
stored_power_scale = self._vehicle_power_scale or 1,
|
||||
--race data
|
||||
stored_last_checkpoint = self._last_checkpoint,
|
||||
stored_total_laps = self._total_laps,
|
||||
@ -196,6 +198,33 @@ function automobiles_lib.get_staticdata(self)
|
||||
})
|
||||
end
|
||||
|
||||
local function scale_entity(self, scale)
|
||||
scale = scale or 1
|
||||
local initial_properties = automobiles_lib.properties_copy(self.initial_properties)
|
||||
local new_properties = automobiles_lib.properties_copy(initial_properties)
|
||||
|
||||
--[[if initial_properties.collisionbox then
|
||||
for i, value in ipairs(initial_properties.collisionbox) do
|
||||
new_properties.collisionbox[i] = value * scale
|
||||
--core.log("action", new_properties.collisionbox[i])
|
||||
end
|
||||
end
|
||||
|
||||
if initial_properties.selectionbox then
|
||||
for i, value in ipairs(initial_properties.selectionbox) do
|
||||
new_properties.selectionbox[i] = value * scale
|
||||
end
|
||||
end]]--
|
||||
|
||||
if initial_properties.stepheight then
|
||||
new_properties.stepheight = initial_properties.stepheight * scale
|
||||
end
|
||||
|
||||
new_properties.visual_size = {x=scale, y=scale}
|
||||
|
||||
self.object:set_properties(new_properties)
|
||||
end
|
||||
|
||||
function automobiles_lib.on_activate(self, staticdata, dtime_s)
|
||||
if staticdata ~= "" and staticdata ~= nil then
|
||||
local data = minetest.deserialize(staticdata) or {}
|
||||
@ -217,6 +246,8 @@ function automobiles_lib.on_activate(self, staticdata, dtime_s)
|
||||
|
||||
self._car_type = data.stored_car_type
|
||||
self._car_gravity = data.stored_car_gravity or -automobiles_lib.gravity
|
||||
self._vehicle_scale = data.stored_scale or 1
|
||||
self._vehicle_power_scale = data.stored_power_scale or 1
|
||||
|
||||
automobiles_lib.setText(self, self._vehicle_name)
|
||||
if data.remove then
|
||||
@ -226,11 +257,14 @@ function automobiles_lib.on_activate(self, staticdata, dtime_s)
|
||||
end
|
||||
end
|
||||
|
||||
scale_entity(self, self._vehicle_scale)
|
||||
|
||||
if self._painting_load then
|
||||
self._painting_load(self, self._color)
|
||||
else
|
||||
automobiles_lib.paint(self, self._color)
|
||||
end
|
||||
|
||||
local pos = self.object:get_pos()
|
||||
|
||||
local front_suspension=minetest.add_entity(self.object:get_pos(),self._front_suspension_ent)
|
||||
@ -279,7 +313,12 @@ function automobiles_lib.on_activate(self, staticdata, dtime_s)
|
||||
steering:set_attach(self.steering_axis,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
|
||||
self.steering = steering
|
||||
else
|
||||
self.object:set_bone_position("drive_adjust", self._drive_wheel_pos, {x=self._drive_wheel_angle, y=0, z=0})
|
||||
self.object:set_bone_override("drive_adjust", {
|
||||
position = {self._drive_wheel_pos, absolute = false},
|
||||
rotation = {self._drive_wheel_angle, absolute = false}
|
||||
})
|
||||
|
||||
--self.object:set_bone_position("drive_adjust", self._drive_wheel_pos, {x=self._drive_wheel_angle, y=0, z=0})
|
||||
end
|
||||
|
||||
if self._rag_retracted_ent then
|
||||
@ -359,6 +398,7 @@ end
|
||||
|
||||
function automobiles_lib.on_step(self, dtime)
|
||||
automobiles_lib.stepfunc(self, dtime)
|
||||
|
||||
--[[sound play control]]--
|
||||
self._last_time_collision_snd = self._last_time_collision_snd + dtime
|
||||
if self._last_time_collision_snd > 1 then self._last_time_collision_snd = 1 end
|
||||
@ -368,6 +408,8 @@ function automobiles_lib.on_step(self, dtime)
|
||||
|
||||
--in case it's not declared
|
||||
self._max_acc_factor = self._max_acc_factor or 1
|
||||
self._vehicle_scale = self._vehicle_scale or 1
|
||||
self._vehicle_power_scale = self._vehicle_power_scale or self._vehicle_scale
|
||||
|
||||
local rotation = self.object:get_rotation()
|
||||
local yaw = rotation.y
|
||||
@ -387,18 +429,19 @@ function automobiles_lib.on_step(self, dtime)
|
||||
local dynamic_later_drag = self._LATER_DRAG_FACTOR
|
||||
if longit_speed > 2 then dynamic_later_drag = 2.0 end
|
||||
if longit_speed > 8 then dynamic_later_drag = 0.5 end
|
||||
--core.chat_send_all(dump(longit_speed))
|
||||
|
||||
if automobiles_lib.extra_drift and longit_speed > 4 then
|
||||
if automobiles_lib.extra_drift and longit_speed > (4*self._vehicle_power_scale) then
|
||||
dynamic_later_drag = dynamic_later_drag/(longit_speed*2)
|
||||
end
|
||||
|
||||
local later_drag = 0
|
||||
local later_drag = vector.new()
|
||||
if self._is_motorcycle == true then
|
||||
later_drag = vector.multiply(nhdir,later_speed*
|
||||
later_speed*self._LATER_DRAG_FACTOR*-1*automobiles_lib.sign(later_speed))
|
||||
else
|
||||
later_drag = vector.multiply(nhdir,later_speed*
|
||||
later_speed*dynamic_later_drag*-1*automobiles_lib.sign(later_speed))
|
||||
later_speed*dynamic_later_drag*-1*automobiles_lib.sign(later_speed))
|
||||
end
|
||||
|
||||
local accel = vector.add(longit_drag,later_drag)
|
||||
@ -514,23 +557,23 @@ function automobiles_lib.on_step(self, dtime)
|
||||
--control
|
||||
local steering_angle_max = 40
|
||||
local steering_speed = 40
|
||||
if math.abs(longit_speed) > 3 then
|
||||
if math.abs(longit_speed) > 3*self._vehicle_scale then
|
||||
local mid_speed = (steering_speed/2)
|
||||
steering_speed = mid_speed + mid_speed / math.abs(longit_speed*0.25)
|
||||
steering_speed = (mid_speed + (mid_speed / math.abs(longit_speed*0.25))*self._vehicle_scale)
|
||||
end
|
||||
|
||||
--adjust engine parameter (transmission emulation)
|
||||
local acc_factor = self._max_acc_factor
|
||||
local transmission_state = automobiles_lib.get_transmission_state(longit_speed, self._max_speed)
|
||||
local transmission_state = automobiles_lib.get_transmission_state(self, longit_speed, self._max_speed)
|
||||
|
||||
local target_acc_factor = acc_factor
|
||||
|
||||
if self._have_transmission ~= false then
|
||||
if transmission_state == 1 then
|
||||
target_acc_factor = (self._max_acc_factor/3)
|
||||
target_acc_factor = (acc_factor/3)
|
||||
end
|
||||
if transmission_state == 2 then
|
||||
target_acc_factor = (self._max_acc_factor/2)
|
||||
target_acc_factor = (acc_factor/2)
|
||||
end
|
||||
self._transmission_state = transmission_state
|
||||
end
|
||||
@ -542,6 +585,7 @@ function automobiles_lib.on_step(self, dtime)
|
||||
control = self._control_function
|
||||
end
|
||||
accel, stop = control(self, dtime, hull_direction, longit_speed, longit_drag, later_drag, accel, target_acc_factor, self._max_speed, steering_angle_max, steering_speed)
|
||||
--accel = vector.multiply(accel, self._vehicle_power_scale)
|
||||
else
|
||||
self._show_lights = false
|
||||
if self.sound_handle ~= nil then
|
||||
@ -686,17 +730,17 @@ function automobiles_lib.on_step(self, dtime)
|
||||
self.object:set_acceleration({x=0,y=0,z=0})
|
||||
self.object:set_velocity({x=0,y=0,z=0})
|
||||
else
|
||||
self._last_accel = accel
|
||||
self.object:move_to(curr_pos)
|
||||
--airutils.set_acceleration(self.object, new_accel)
|
||||
local limit = (self._max_speed/self.dtime)
|
||||
if accel.y > limit then accel.y = limit end --it isn't a rocket :/
|
||||
self._last_accel = accel
|
||||
end
|
||||
|
||||
self._last_ground_check = self._last_ground_check + dtime
|
||||
if self._last_ground_check > 0.18 then
|
||||
self._last_ground_check = 0
|
||||
automobiles_lib.ground_get_distances(self, 0.372, (self._front_suspension_pos.z)/10)
|
||||
automobiles_lib.ground_get_distances(self, 0.372*self._vehicle_scale, (self._front_suspension_pos.z*self._vehicle_scale)/10)
|
||||
end
|
||||
local newpitch = self._pitch --velocity.y * math.rad(6)
|
||||
|
||||
@ -745,7 +789,7 @@ function automobiles_lib.on_step(self, dtime)
|
||||
local min_later_speed = self._min_later_speed or 3
|
||||
local speed_for_smoke = min_later_speed / 2
|
||||
if (later_speed > speed_for_smoke or later_speed < -speed_for_smoke) and not self._is_motorcycle then
|
||||
automobiles_lib.add_smoke(curr_pos, yaw, self._rear_wheel_xpos)
|
||||
automobiles_lib.add_smoke(self, curr_pos, yaw, self._rear_wheel_xpos*self._vehicle_scale)
|
||||
if automobiles_lib.extra_drift == false then --disables the sound when playing drift game.. it's annoying
|
||||
if self._last_time_drift_snd >= 2.0 and (later_speed > min_later_speed or later_speed < -min_later_speed) then
|
||||
self._last_time_drift_snd = 0
|
||||
|
@ -89,13 +89,13 @@ function automobiles_lib.properties_copy(origin_table)
|
||||
return tablecopy
|
||||
end
|
||||
|
||||
local function smoke_particle(pos)
|
||||
local function smoke_particle(self, pos)
|
||||
minetest.add_particle({
|
||||
pos = pos,
|
||||
velocity = {x = 0, y = 0, z = 0},
|
||||
acceleration = {x = 0, y = 0, z = 0},
|
||||
expirationtime = 0.25,
|
||||
size = 2.8,
|
||||
size = 2.8*(self._vehicle_scale or 1),
|
||||
collisiondetection = false,
|
||||
collision_removal = false,
|
||||
vertical = false,
|
||||
@ -103,7 +103,7 @@ local function smoke_particle(pos)
|
||||
})
|
||||
end
|
||||
|
||||
function automobiles_lib.add_smoke(pos, yaw, rear_wheel_xpos)
|
||||
function automobiles_lib.add_smoke(self, pos, yaw, rear_wheel_xpos)
|
||||
local direction = yaw
|
||||
|
||||
--right
|
||||
@ -112,7 +112,7 @@ function automobiles_lib.add_smoke(pos, yaw, rear_wheel_xpos)
|
||||
smk_pos.x = smk_pos.x + move * math.cos(direction)
|
||||
smk_pos.z = smk_pos.z + move * math.sin(direction)
|
||||
|
||||
smoke_particle(smk_pos)
|
||||
smoke_particle(self, smk_pos)
|
||||
|
||||
--left
|
||||
direction = direction - math.rad(180)
|
||||
@ -120,7 +120,7 @@ function automobiles_lib.add_smoke(pos, yaw, rear_wheel_xpos)
|
||||
smk_pos.x = smk_pos.x + move * math.cos(direction)
|
||||
smk_pos.z = smk_pos.z + move * math.sin(direction)
|
||||
|
||||
smoke_particle(smk_pos)
|
||||
smoke_particle(self, smk_pos)
|
||||
end
|
||||
|
||||
--returns 0 for old, 1 for new
|
||||
@ -176,6 +176,8 @@ function automobiles_lib.attach_driver(self, player)
|
||||
if automobiles_lib.detect_player_api(player) == 1 then
|
||||
eye_y = 2.5
|
||||
end
|
||||
eye_y = eye_y*self._vehicle_scale
|
||||
|
||||
player:set_eye_offset({x = 0, y = eye_y, z = 0}, {x = 0, y = eye_y, z = -30})
|
||||
player_api.player_attached[name] = true
|
||||
|
||||
@ -242,6 +244,7 @@ function automobiles_lib.attach_pax(self, player, onside)
|
||||
if automobiles_lib.detect_player_api(player) == 1 then
|
||||
eye_y = 2.5
|
||||
end
|
||||
eye_y = eye_y*self._vehicle_scale
|
||||
|
||||
if self._passenger == nil then
|
||||
self._passenger = name
|
||||
@ -553,8 +556,13 @@ end
|
||||
|
||||
function automobiles_lib.engine_set_sound_and_animation(self, _longit_speed)
|
||||
--minetest.chat_send_all('test1 ' .. dump(self._engine_running) )
|
||||
local abs_curr_long_speed = math.abs(self._longit_speed)
|
||||
local abs_long_speed = math.abs(_longit_speed)
|
||||
local scale = self._vehicle_power_scale
|
||||
local range_spacing = 0.01
|
||||
if self.sound_handle then
|
||||
if (math.abs(self._longit_speed) > math.abs(_longit_speed) + 0.03) or (math.abs(self._longit_speed) + 0.03 < math.abs(_longit_speed)) then
|
||||
if (abs_curr_long_speed*scale > (abs_long_speed + range_spacing)*scale)
|
||||
or ((abs_curr_long_speed + range_spacing)*scale < abs_long_speed*scale) then
|
||||
--minetest.chat_send_all('test2')
|
||||
automobiles_lib.engineSoundPlay(self)
|
||||
end
|
||||
@ -682,9 +690,11 @@ function automobiles_lib.paint_with_mask(self, colstr, mask_colstr, target_textu
|
||||
end
|
||||
|
||||
-- very basic transmission emulation for the car
|
||||
function automobiles_lib.get_transmission_state(curr_speed, max_speed)
|
||||
function automobiles_lib.get_transmission_state(self, curr_speed, max_speed)
|
||||
local retVal = 1
|
||||
max_speed = max_speed or 100
|
||||
max_speed = max_speed*self._vehicle_scale
|
||||
curr_speed = curr_speed*self._vehicle_scale
|
||||
if curr_speed >= (max_speed/4) then retVal = 2 end
|
||||
if curr_speed >= (max_speed/2) then retVal = 3 end
|
||||
return retVal
|
||||
|
Loading…
Reference in New Issue
Block a user