From ca55c6f3c0ddb5d524425088aba9a12b49812f8e Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sat, 18 Nov 2017 12:38:25 +0100 Subject: [PATCH] =?UTF-8?q?Change=20Y=20rotation=20from=2045=C2=B0=20to=20?= =?UTF-8?q?30=C2=B0.=20Only=20send=20velocity=20when=20required.=20Smoothe?= =?UTF-8?q?r=20position=20correction=20when=20the=20X,Y,Z=20directions=20w?= =?UTF-8?q?eren't=20changed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cart_entity.lua | 29 +++++++++++++++++++---------- functions.lua | 2 +- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/cart_entity.lua b/cart_entity.lua index 69f45fb..deeed2e 100644 --- a/cart_entity.lua +++ b/cart_entity.lua @@ -214,6 +214,7 @@ function cart_entity:on_step(dtime) local dir, switch_keys = boost_cart:get_rail_direction( pos, cart_dir, ctrl, self.old_switch, self.railtype ) + local dir_changed = not vector.equals(dir, self.old_dir) local new_acc = {x=0, y=0, z=0} if stop_wiggle or vector.equals(dir, {x=0, y=0, z=0}) then @@ -230,7 +231,7 @@ function cart_entity:on_step(dtime) update.vel = true else -- Direction change detected - if not vector.equals(dir, self.old_dir) then + if dir_changed then vel = vector.multiply(dir, v3_len(vel)) update.vel = true if dir.y ~= self.old_dir.y then @@ -352,29 +353,37 @@ function cart_entity:on_step(dtime) anim = {x=2, y=2} end self.object:set_animation(anim, 1, 0) + + -- Change player model rotation, depending on the Y direction if player and dir.y ~= old_y_dir then local feet = {x=0, y=0, z=0} local eye = {x=0, y=-4, z=0} - feet.y = boost_cart.old_player_model and 6 or -4.2 + feet.y = boost_cart.old_player_model and 6 or -4 if dir.y ~= 0 then -- TODO: Find a better way to calculate this if boost_cart.old_player_model then - feet.y = 6 + 1.5 - feet.z = -dir.y * 7 + feet.y = feet.y + 2 + feet.z = -dir.y * 6 else - feet.y = -4.2 + 3 - feet.z = -dir.y + feet.y = feet.y + 4 + feet.z = -dir.y * 2 end - eye.z = -dir.y * 10 + eye.z = -dir.y * 8 end player:set_attach(self.object, "", feet, - {x=dir.y * -45, y=0, z=0}) + {x=dir.y * -30, y=0, z=0}) player:set_eye_offset(eye, eye) end - self.object:set_velocity(vel) + if update.vel then + self.object:set_velocity(vel) + end if update.pos then - self.object:set_pos(pos) + if dir_changed then + self.object:set_pos(pos) + else + self.object:move_to(pos) + end end end diff --git a/functions.lua b/functions.lua index e078a24..1d1498c 100644 --- a/functions.lua +++ b/functions.lua @@ -18,7 +18,7 @@ function boost_cart:manage_attachment(player, obj) default.player_attached[player_name] = status if status then - local y_pos = self.old_player_model and 6 or -4.2 + local y_pos = self.old_player_model and 6 or -4 player:set_attach(obj, "", {x=0, y=y_pos, z=0}, {x=0, y=0, z=0}) player:set_eye_offset({x=0, y=-4, z=0},{x=0, y=-4, z=0}) else