Fix train collision and coupling on opposing trains, and try to implement animation (currently does not work)
parent
e449704a92
commit
a879ce8d3c
|
@ -219,4 +219,7 @@ function advtrains.get_real_index_position(path, index)
|
|||
end
|
||||
function advtrains.pos_median(pos1, pos2)
|
||||
return {x=pos1.x-(pos1.x-pos2.x)*0.5, y=pos1.y-(pos1.y-pos2.y)*0.5, z=pos1.z-(pos1.z-pos2.z)*0.5}
|
||||
end
|
||||
function advtrains.abs_ceil(i)
|
||||
return math.ceil(math.abs(i))*math.sign(i)
|
||||
end
|
Binary file not shown.
Binary file not shown.
|
@ -33,8 +33,8 @@ function advtrains.hud_train_format(train, flip)
|
|||
if flip then fct=-1 end
|
||||
if not train then return "" end
|
||||
local max=advtrains.all_traintypes[train.traintype].max_speed or 10
|
||||
local vel=math.ceil(train.velocity)*fct
|
||||
local tvel=math.ceil(train.tarvelocity)*fct
|
||||
local vel=advtrains.abs_ceil(train.velocity)*fct
|
||||
local tvel=advtrains.abs_ceil(train.tarvelocity)*fct
|
||||
local firstLine, secondLine
|
||||
if vel<0 then
|
||||
firstLine="Speed: <"..string.rep("_", vel+max)..string.rep("+", -vel).."|"..string.rep("_", max)..">"
|
||||
|
|
|
@ -574,16 +574,18 @@ function advtrains.try_connect_trains_and_check_collision(id1, id2)
|
|||
for i=(advtrains.get_train_end_index(train2)+0.5),train2.index-0.5 do
|
||||
local testpos=advtrains.get_real_index_position(train2.path,i)
|
||||
if vector.distance(testpos, backpos1) < 0.5 then
|
||||
local v2_sign = math.sign(i - ((train2.index-0.5) - ( (train2.index-0.5)-(advtrains.get_train_end_index(train2)+0.5) / 2 )))
|
||||
--TODO physics
|
||||
train1.velocity=1
|
||||
train2.velocity=-1
|
||||
train2.velocity=v2_sign
|
||||
train1.recently_collided_with_env=true
|
||||
train2.recently_collided_with_env=true
|
||||
return
|
||||
end
|
||||
if vector.distance(testpos, frontpos1) < 0.5 then
|
||||
local v2_sign = math.sign(i - ((train2.index-0.5) - ( (train2.index-0.5)-(advtrains.get_train_end_index(train2)+0.5) / 2 )))
|
||||
train1.velocity=-1
|
||||
train2.velocity=1
|
||||
train2.velocity=v2_sign
|
||||
train1.recently_collided_with_env=true
|
||||
train2.recently_collided_with_env=true
|
||||
return
|
||||
|
@ -680,7 +682,7 @@ function advtrains.invert_train(train_id)
|
|||
|
||||
local old_path=advtrains.get_or_create_path(train_id, train)
|
||||
train.path={}
|
||||
train.index= - advtrains.get_train_end_index(train1)
|
||||
train.index= - advtrains.get_train_end_index(train)
|
||||
train.velocity=-train.velocity
|
||||
train.tarvelocity=-train.tarvelocity
|
||||
for k,v in pairs(old_path) do
|
||||
|
|
14
wagons.lua
14
wagons.lua
|
@ -268,6 +268,9 @@ function wagon:on_step(dtime)
|
|||
self.object:setvelocity(velocityvec)
|
||||
self.object:setyaw(yaw)
|
||||
self.updatepct_timer=2
|
||||
if self.update_animation then
|
||||
self:update_animation(gp.velocity)
|
||||
end
|
||||
end
|
||||
|
||||
self.old_velocity_vector=velocityvec
|
||||
|
@ -336,6 +339,11 @@ advtrains.register_wagon("greenwagon", "steam",{textures = {"green.png"}})
|
|||
advtrains.register_wagon("redwagon", "steam",{textures = {"red.png"}})
|
||||
advtrains.register_wagon("yellowwagon", "steam",{textures = {"yellow.png"}})
|
||||
]]
|
||||
|
||||
--[[
|
||||
wagons can define update_animation(self, velocity) if they have a speed-dependent animation
|
||||
this function will be called when the velocity vector changes or every 2 seconds.
|
||||
]]
|
||||
advtrains.register_wagon("newlocomotive", "steam",{
|
||||
mesh="newlocomotive.b3d",
|
||||
textures = {"advtrains_newlocomotive.png"},
|
||||
|
@ -345,6 +353,12 @@ advtrains.register_wagon("newlocomotive", "steam",{
|
|||
visual_size = {x=1, y=1},
|
||||
wagon_span=1.85,
|
||||
collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
|
||||
update_animation=function(self, velocity)
|
||||
if self.old_anim_velocity~=advtrains.abs_ceil(velocity) then
|
||||
self.object:set_animation({x=1,y=60}, math.floor(velocity))
|
||||
self.old_anim_velocity=advtrains.abs_ceil(velocity)
|
||||
end
|
||||
end
|
||||
})
|
||||
advtrains.register_wagon("wagon_default", "steam",{
|
||||
mesh="wagon.b3d",
|
||||
|
|
Loading…
Reference in New Issue