Collision "problem"
Blitz3D Forums/Blitz3D Programming/Collision "problem"
| ||
Not sure if this should be considered a bug or not. If you have a collision between two entitys and then free the entity that was collided with (the one that didn't move) it is still listed in the collision list. Try this: Graphics3D 800,600,16,2 SetBuffer BackBuffer() Camera=CreateCamera() PositionEntity Camera,0,0,-20 ;Create 2 spheres and position them apart Sphere1=CreateSphere() Print "Sphere 1 - "+Sphere1 PositionEntity Sphere1,-5,0,0 EntityRadius Sphere1,1 EntityType Sphere1,1 ResetEntity Sphere1 Sphere2=CreateSphere() Print "Sphere 2 - "+Sphere2 PositionEntity Sphere2,5,0,0 EntityRadius Sphere2,1 EntityType Sphere2,1 ResetEntity Sphere2 ;Generate a collision by moving sphere1 into sphere2 Collisions 1,1,2,1 TranslateEntity Sphere1,15,0,0 UpdateWorld FreeEntity Sphere2 ;NOTE: Try disabling this line ;Display collision info Print For a=1 To CountCollisions(Sphere1) ent=CollisionEntity(Sphere1,a) typ=GetEntityType(ent) Print "Hit "+ent+" (type: "+typ+")" Next WaitKey End This isn't exactly a bug, but it would be very helpful if blitz removed the entity from the list of collisions. Sorry if this has been discussed before, but I couldn't see anything obvious from a couple of quick searches |
| ||
The sphere2 was present in the world when you call updateworld() so it's logical that it is still present in the collision list. If you remove it before updateworld() then it shouldn't appear. |
| ||
Yes i am aware of that and I agree it makes sense logically. But when you make a very complex game it becomes very hard to ensure no entities are free'd between updateworld and checking a list of collisions. Personally I search though my own lists of entitys to determine the entity type as it doesn't result in a crash (I can cancel silently) Feature request: +Remove free'd entitys from collision list +Or at the very least make a clear note in the documentation warning of this |
| ||
Just a pointless thought then... change the way you write your code. |
| ||
I was only making a suggestion which might be fairly easy to do (I don't know, I could be wrong) and save a lot of people trouble. Anyone who doesn't know that it works this way is quite likely to fall into the trap like I did... If you prefer I won't make any suggestions that can help others. Doesn't matter to me anyway, as I said I can get around it by doing things other ways... or I suppose I could go through a few thousand lines and make sure I'm not free'ing any entity between updateworld and checking the collision list. If I was aware it worked that way to start with I would have been more careful while coding and avoid using freeentity... but its not an obvious, so a note in the documentation would help. I'm not saying its a bug, I'm not saying it shouldn't work this way (thats why I posted in the first place, to see what others thought).. I'm just making a suggestion.. jesh. |
| ||
Rook's been a bit funny lately. ignore him :) hehe To be honest this is something that i didnt think of and may be causing issues in a few of my older projects. Cheers for pointing it out.... |
| ||
maybe try to hide the entity before you free it. |
| ||
ah, good some nice replys :) Yup I was thinking I could replace all freeentitys with a system that hides the entity, waits a couple of frames then frees it to ensure nothing is left in the collision list. |
| ||
As far as I know you even don't need to wait since hideentity will clear the entities collision list immediately - well you can test it. |
| ||
Tested it, it probably clears its own list but the problem is when its on another entitys list good thought though |
| ||
I had a similar problem where particular entities were involved in more than one collision in the same UpdateWorld. As the code cycled through each collision, created an explosion and freed the entity, it would give me an "Entity Doesn't Exist" error. The solution? Rather than delete the collision entities in your main program, add them to an array. Create a function called ActOnCollisions() and call it before UpdateWorld. Cycle through the array and remove duplicate entities. Cycle through again and delete the entities... No more "Entity Doesn't Exist" errors. |
| ||
King Dave Agreed - I was having the exact same prob - so destroyed entities are hidden first and then freed in the following cycle. |