I want to achieve that after my LineTracer (a car that dragged from a menu of Model Browser on the left of Copprliasim Edu 4.1.0 interface) collide with a wall, then set its position to a place(by sim.setObjectPosition), and continue to drive it. btw... I drive my car with a external Joystick.
And, I've searched from this Forum and got that I should use code as following:
Code: Select all
sim.setThreadAutomaticSwitch(false)
sim.getObjectsInTree(lineTracer,sim.handle_all,0)
sim.resetDynamicObject(sim.handle_all)
sim.setObjectPosition(lineTracer,-1,{0.66924,-0.050004,0.027544})
sim.setObjectOrientation(lineTracer,-1,{0,8.998,-0.018})
sim.setThreadAutomaticSwitch(true)
Code: Select all
local current_state_2=sim.checkCollision(car_body,stop)
if(current_state_2==1)then
dialog_H=sim.displayDialog('Congratulations','You finish the task!', sim.dlgstyle_message, true)
sleep(3)
sim.setThreadAutomaticSwitch(false)
sim.getObjectsInTree(lineTracer,sim.handle_all,0)
sim.resetDynamicObject(sim.handle_all)
sim.setObjectPosition(lineTracer,-1,{0.66924,-0.050004,0.027544})
sim.setObjectOrientation(lineTracer,-1,{0,8.998,-0.018})
sim.setThreadAutomaticSwitch(true)
end
When I use a new scene with only a car and a wall, and input my code mentioned above. after the car back to the place I set, it will shake, or turn over, or have other strange behavior. And I don't know how to solve it, please help me!