a moving object's position is not changing in infinitefloor

Typically: "How do I... ", "How can I... " questions
Post Reply
xxm
Posts: 28
Joined: 26 Oct 2020, 09:36

a moving object's position is not changing in infinitefloor

Post by xxm »

Hello,everyone

I want a infinite floor,and when model is moving,object's position is also changing .But when i choose a infiniterFloor.ttm scence, the model's position is not changing ,but i need the position message . I do not know what should i do so that i can get a infinite floor ,and position message change with moving.

Look forward to your replay!

coppelia
Site Admin
Posts: 10339
Joined: 14 Dec 2012, 00:25

Re: a moving object's position is not changing in infinitefloor

Post by coppelia »

Hello,

the infinite floor is designed to keep the robot (or scene content) near the origin. In order to get an idea of travelled distances, you'll have to extract the x/y distance that the floor corrected. For that, open the child script attached to the infinite floor, and add:

Code: Select all

    totalShift={0,0}
at the end of the initialization function. Then add:

Code: Select all

    totalShift[1]=totalShift[1]+dx
    totalShift[2]=totalShift[2]+dy
    print(totalShift)
at the end of the actuation function. That will print the total shift the floor did. So you'll simply have to add that shift to the position of your robot, to get the real travelled distance.

Simplest is to put that shift in a string signal (also at the end of the actuation function):

Code: Select all

    sim.setStringSignal('floorShift',sim.packTable(totalShift))
and in your robot's script, you can do:

Code: Select all

    local robotPosition=sim.getObjectPosition(robotHandle,-1)
    local data=sim.getStringSignal('floorShift')
    if data then
        data=sim.unpackTable(data)
        robotPosition[1]=robotPosition[1]+data[1]
        robotPosition[2]=robotPosition[2]+data[2]
    end
Cheers

Post Reply