When not colliding at ghostcontrol
NO|>>>>>|
NO|>>>>>|
NO|>>>>>|
NO|>>>>>|
NO|>>>>>|
NO|>>>>>|
NO|>>>>>|
NO|>>>>>|
…
When this colliding to ghostcontrol
NO|>>>>>|
NO|>>>>>|
NO|>>>>>|
NO|>>>>>|
NO|>>>>>|
NO|>>>>>|
NO|>>>>>|
NO|>>>>>|
SI|>>>>>>>>>>|
SI|>>>>>>>>>>|
SI|>>>>>>>>>>|
SI|>>>>>>>>>>|
SI|>>>>>>>>>>|
SI|>>>>>>>>>>|
SI|>>>>>>>>>>|
SI|>>>>>>>>>>|
SI|>>>>>>>>>>|
SI|>>>>>>>>>>|
NO|>>>>>|
NO|>>>>>|
NO|>>>>>|
NO|
…
I understand that two threads are running and that something happens. (RenderThread and MainThread).
I want to go through the ghostcontrol only print just a “SI”.
haha @normen, that was very funny . But his question was “just A Si” (i think that “si” means yes). so, the solution is to either remove this control when you detect the vehicule the first time (if you want to use it for only one vehicle) or use an “already triggered vehicle” collection and add the vehicle in it when you detect it the first time. For the second case, if you have a very fast “car cycle” (i.e. you create and delete a lot of car every second) you can also add a value in the userdata of the spatial, so you’ll not have a growing collection and a memory leak.
About nothing, you should either chose to write all your code in english or in your own native language, but a mix of it is kind of ugly. And you should use english if you want help.
I also, sometimes, put french in my code, but i try to remove it as much as i can.
you would want to use a weak hashmap if you wanted to do a collection like that. but i wouldnt go that route…
another route is to just do a check on whether it’s effect has already happened.
for instance if colliding in to the ghost control is what calls carControl.explode(); then inside of explode() do a check to make sure the car isnt already exploding when explode() is called (and if it is just dont process the rest of the method…) if carControl.explode() gets called 20 times in a row so what? a small if statement has no real bearing on anything.
You might want to implement that sort of check any way since you might have various things that could make your car explode for example, and if they both happen at the same time you dont want the car to explode twice.
Yeah I think he means that he only wants to deal with the collision event once, in which case it would be the easiest solution to calculate the time between collisions and deem, for example, a 200ms gap a new collision, else ignore it.
(@normen) I’m sorry, I do not make myself clear.
Specifically:
I have a car, to go through this ghostcontrol should increase points of a counter. (I put that “YES” and “NO” to simplify understanding).
Until now when the vehicle collides and remains there, the counter would go to infinity! The idea is that if you are within ghostcontrol add one point, when you leave there, and if colliding again add another point.
@bubuche consider what to write in only one language, preferably do it in English to explain it better and for cleaner code.
@icamefromspace I understand your idea, but what happens if instead, want to increase counter score.
The collision reports happen on the physics tick. So if you check if theres a collision each physics tick that means you still collide with the object. If a physics tick passes without a collision report the objects don’t collide anymore.
Thanks to @t0neg0d by example. What I can not achieve is to change the contact to false, if the vehicle has already passed the ghostcontrol and this out of this.
Does collision(PhysicsCollisionEvent event) recent an update whether or not a collision happens? From the output of your original post, it seems as if it does. Or is it receiving updates from other objects colliding? That would weigh heavily on how I would proceed.
If it is, everything can be handled in the collision method.
Otherwise, you’ll have to use the suggestion above and track elapsed time since the last collision in an update loop. If it reaches whatever threshold you set up for it, then reset and wait for the next collision:
@normen said:
The collision reports happen on the physics tick. So if you check if theres a collision each physics tick that means you still collide with the object. If a physics tick passes without a collision report the objects don't collide anymore.