In the experiment I’m doing, it appears that fixedUpdate
is never called. It’s supposed to be called on each physics update, according to the docs. Is it perhaps the wrong name, or what?
Following example too big to be a bug report, it’s just what I’m working on. Note that the update
is called but fixedUpdate
isn’t.
-- CoCraTu-007
function setup()
scene = craft.scene()
depth = -10
scene.physics.gravity = vec3(0,0,0)
ball = scene:entity()
BallBody = ball:add(craft.rigidbody, DYNAMIC, 1) -- mass 1
BallBody.sleepingAllowed = false
ball.position = vec3(0,depth,0)
ball:add(craft.shape.sphere, 1)
ball.model = craft.model.icosphere(1)
ball.material = craft.material(asset.builtin.Materials.Standard)
ball.material.diffuse = color(255,0,0)
reporter = ball:add(Reporter)
scene.camera:add(OrbitViewer, vec3(0,0,0), 60, 0, 1000)
end
function update(dt)
scene.debug:line(vec3(-10,depth-1,0), vec3(10,depth-1,0), color(255))
scene:update(dt)
end
function draw()
update(DeltaTime)
scene:draw()
reporter:draw()
end
function touched(touch)
if touch.state == BEGAN then
BallBody:applyForce(vec3(0,10,0))
print("force applied")
end
end
Reporter = class()
function Reporter:init(entity)
self.entity = entity
self.lastDrawTime = ElapsedTime
self.lastFixTime = ElapsedTime
self.deltaDrawTime = 0
self.deltaFixTime = 0
end
function Reporter:fixedUpdate(arg)
print(arg)
self.deltaFixTime = ElapsedTime - self.lastFixTime
self.lastFixTime = ElapsedTime
end
function Reporter:update()
self.deltaDrawTime = ElapsedTime - self.lastDrawTime
self.lastDrawTime = ElapsedTime
end
function Reporter:draw()
pushStyle()
textAlign(LEFT)
textMode(LEFT)
fill(255)
text("Draw Time "..self.deltaDrawTime, 400, 100)
text("Fixed Time "..self.deltaFixTime, 400, 80)
text("Vel "..BallBody.linearVelocity.y, 400, 60)
popStyle()
end