From caf2bda7bc02f0bbe6dbbeb415e7881158d143b9 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Thu, 26 Apr 2018 23:35:19 +0200 Subject: Fix path_dir to actually be an angle, path item deletion and orientation of wagons The occupation system as it is now will change. For each position, I will save the index in the train's path, and implement a callback system. I need this because the occupation window system will not be enough to cover all use cases (e.g. to make a train stop with it's center or back at a certain position, I need 3 different brake distances, which doesn't fit into the scheme) --- advtrains/wagons.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'advtrains/wagons.lua') diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua index c3217e2..bf128d9 100644 --- a/advtrains/wagons.lua +++ b/advtrains/wagons.lua @@ -185,7 +185,7 @@ function wagon:destroy() if data.train_id and self:train() then table.remove(self:train().trainparts, data.pos_in_trainparts) - advtrains.update_trainpart_properties(self.train_id) + advtrains.update_trainpart_properties(data.train_id) advtrains.wagons[self.id]=nil if self.discouple then self.discouple.object:remove() end--will have no effect on unloaded objects return true @@ -196,6 +196,7 @@ function wagon:destroy() self.object:remove() end +local pihalf = math.pi/2 function wagon:on_step(dtime) return advtrains.pcall(function() @@ -375,9 +376,11 @@ function wagon:on_step(dtime) -- Calculate new position, yaw and direction vector local index = advtrains.path_get_index_by_offset(train, train.index, -data.pos_in_train) - local pos, yaw, npos, npos2 = advtrains.path_get_interpolated(train, index) + local pos, tyaw, npos, npos2 = advtrains.path_get_interpolated(train, index) local vdir = vector.normalize(vector.subtract(npos2, npos)) + local yaw = tyaw - pihalf + --automatic get_on --needs to know index and path if self.door_entry and train.door_open and train.door_open~=0 and train.velocity==0 then @@ -478,7 +481,7 @@ function wagon:on_step(dtime) self.player_yaw[name] = p:get_look_horizontal()-self.old_yaw end -- set player looking direction using calculated offset - p:set_look_horizontal((self.player_yaw[name] or 0)+yaw) + --TODO p:set_look_horizontal((self.player_yaw[name] or 0)+yaw) end end self.turning = true -- cgit v1.2.3