Game + Physics time steps BETA testing

Not sure if this is the right thread @Mathias_Westerdahl, but I’m experimenting with the fixed_update in our current project (using the Defold version v1.3.1).

When using fixed_update to add force, the game object seems to stutter while moving. While moving it to a regular update instead, it moves smoothly.

Ex:

go.property("turn_amount", 30)

local left_turn = nil
local right_turn = nil

function init(self)
  left_turn = vmath.vector3(self.turn_amount, 0, 0)
  right_turn = vmath.vector3(-self.turn_amount, 0, 0)
end

function fixed_update(self, dt)
  local turn = vmath.lerp(delta, left_turn, right_turn)["x"] -- no linear lerp function i defold except in vmath
  local turn_quaternion = vmath.quat_axis_angle(vmath.vector3(0, 0, 1), turn * dt) -- set the turn quaternion based on the turn value
  local rot = go.get(".", "rotation") * turn_quaternion -- multiply with the current rotation
  go.set_rotation(rot)

  local forward_speed = 1
  local distance = forward_speed * dt
  local direction = vmath.rotate(rot, vmath.vector3(0, 1, 0)) * distance -- get a direction vector

  pos = go.get(".", "position")
  pos = pos + direction -- add this to the current position

  msg.post(".", "apply_force", {force = direction * 100, position = pos})
end
1 Like