Hello,
I created a scene contained a car and walls. And I can used a joystick to control the car. I want to record the collision times of the car and walls, which means that the car touches with the walls once, the collision time increased by one. But in my scene, when the car touch with walls once, the collision times increased constantly, unless the car leave the walls. Please tell me how to solve this problem and achieve my goal, thanks! The code is following:
collisionTimes=0
local current_state=sim.checkCollision(car,wall)
if(current_state==1 )then --record state collision times
simUI.show(ui) --remind the collision
collisionTimes=collisionTimes+1
else
simUI.hide(ui) --closed the reminder
end
you should only increase the collision count, if the current collision state is true, and previous collision state was false.
But even in that situation, you might experience unwanted counts, when the vehicle is very close to the wall, and constantly enters and leaves a collision state. To solve that issue, you can use two different collision shapes for your vehicle (they could be hidden in an invisible layer). One of them would be slightly larger (e.g. inflated convex hull). See [EMenu bar --> Add --> Inflated convex hull of selection...]
you should only increase the collision count, if the current collision state is true, and previous collision state was false.
But even in that situation, you might experience unwanted counts, when the vehicle is very close to the wall, and constantly enters and leaves a collision state. To solve that issue, you can use two different collision shapes for your vehicle (they could be hidden in an invisible layer). One of them would be slightly larger (e.g. inflated convex hull). See [EMenu bar --> Add --> Inflated convex hull of selection...]
Cheers
Thanks for your reply. And I still have a question: when I add a Inflated convex hull on the vehicle, how to set the collision state? Only when both of the Inflated convex hull and vehicle collide with the wall did collision count increase 1?
if previousCollisionState then
if not largeHullCollides
currentCollisionState=false
end
else
if smallHullCollides then
currentCollisionState=true
end
end
previousCollisionState=currentCollisionState