Hello,
My model is a car. I will control it to run through a maze (not always straight). I defined an initial variable — distance=0. And I want to know how to record the distance it move from the initial position to the end. Thank you for spending your time on answering my question.
model's distance recording
Re: model's distance recording
You can accumulate traveled distance (distance
d
between current position and previous position) in a child script like so:Code: Select all
function sysCall_init()
self=sim.getObjectHandle('.')
distance=0
lastPosition=sim.getObjectPosition(self,-1)
end
function sysCall_sensing()
local p=sim.getObjectPosition(self,-1)
local d=0; for i=1,3 do d=d+math.pow(p[i]-lastPosition[i],2) end; d=math.sqrt(d)
lastPosition=p
distance=distance+d
end
Re: model's distance recording
Thank you so much, fferi!