Skip to content

Commit

Permalink
Fix visual car jittering
Browse files Browse the repository at this point in the history
  • Loading branch information
aglitchman committed Oct 26, 2023
1 parent 65707b3 commit a9954a0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions scene3d/scripts/vehicles/car/car_main.script
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ local function init_car(self)
self.car_data = {
car_mass = go.get(self.chassis_url, "mass"),
car_position = vmath.vector3(0),
car_rotation = vmath.vector4(),
car_rotation = vmath.quat(),
car_euler = vmath.vector3(),
car_previous_position = vmath.vector3(0),
car_visual_position = vmath.vector3(0),
car_velocity = vmath.vector3(0),
car_direction = vmath.vector3(0),
car_speed = 0,
Expand Down Expand Up @@ -136,6 +135,14 @@ function update(self, dt)
end
local c = self.car_data

--
-- UPDATE VISUAL TRANSFORM
--
if c.car_rotation then
go.set_rotation(c.car_rotation, self.visuals_url)
go.set_position(c.car_position, self.visuals_url)
end

--
-- DEBUG
--
Expand All @@ -161,7 +168,6 @@ function fixed_update(self, dt)
local prev_position = c.car_position
local car_position = go.get_position(self.physics_url)
c.car_position = car_position
c.car_visual_position = car_position -- vmath.lerp(dt * 30, c.car_visual_position, car_position)
if vmath.length(car_position - prev_position) < 0.02 then
prev_position = c.car_previous_position
else
Expand All @@ -173,9 +179,6 @@ function fixed_update(self, dt)
c.car_rotation = car_rotation
c.car_euler = go.get(self.physics_url, "euler")

go.set_rotation(c.car_rotation, self.visuals_url)
go.set_position(c.car_visual_position, self.visuals_url)

--
-- CONTROLS
--
Expand Down

0 comments on commit a9954a0

Please sign in to comment.