Question About Collision Times Recording

Typically: "How do I... ", "How can I... " questions
Post Reply
lwang87
Posts: 41
Joined: 24 May 2021, 16:47

Question About Collision Times Recording

Post by lwang87 »

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:

Code: Select all

            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

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

Re: Question About Collision Times Recording

Post by coppelia »

Hello,

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

lwang87
Posts: 41
Joined: 24 May 2021, 16:47

Re: Question About Collision Times Recording

Post by lwang87 »

coppelia wrote: 03 Nov 2021, 10:18 Hello,

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?

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

Re: Question About Collision Times Recording

Post by coppelia »

I would use two inflated convex hulls, that have a different inflation degree. So a larger hull and a small hull. Then something like:

Code: Select all

if previousCollisionState then
    if not largeHullCollides
        currentCollisionState=false
    end
else
    if smallHullCollides then
        currentCollisionState=true
    end
end

previousCollisionState=currentCollisionState
Cheers

Post Reply