Orangatang91
64 posts
|
Hey guys was wondering if there are any other engines that make Box2d coding easier like QuickBox2d. Been having a lot of success with quickbox2d’s easy collision management and object creation. The only real problem I have with it is that grouped objects do not have any body properties, so it is not as easy to manipulate grouped objects. For example: My code groups many box objects which create one level, but to move this level I can only change it’s x and y values rather than giving it’s body the desired b2Vec2 (box2d velocity vector). This seems to cause easy collision bugs with other objects. If there is anyone who knows more about this engine please tell me if there are any other ways of updating a grouped object’s position (or change it’s velocity) without compromising it’s collisions with other objects. And if there are any alternative box2d utilizing engines I would be happy to look thoroughly into them.
[EDIT] PROBLEM SOLVED. GROUP OBJECTS DO HAVE A BODY PROPERTY. MINE JUST DIDN’T WORK BECAUSE I SET MY OBJECTS TO BE STATIC (DENSITY OF ZERO) BEFORE GROUPING THEM.
|
|
|
LearningAS3
83 posts
|
Oh great. This is good engine. I will have a look at it later.
You mentioned collision detection. Well it is something which has been troubling me for sometime. I have a game where there are lot of enemies. Enemies move and try to get near player (specially the melee ones), although their life span is not to great, they overlap for a short time. I wanted them to maintain distance from other enemies. For this I varied their speed and turning angles but still sometimes overlapping happens. Is there a quick and easy way to fix for this. (I had thought of looping through all the enemies inside the enemy update function but I think it will take up too much processing power)
|
|
|
Orangatang91
64 posts
|
If there aren’t that many enemies it shouldn’t take up too much processing power. I would just calculate the distance of each enemy from the others and if any of these distances is too close (which causes overlapping) then have them turn around, or stop, or whatever you think they should do… Alternatively quickbox2d should help you with enemy collisions such that if they do collide, most likely they still will not overlap (as long as these enemies are quickbox2d objects). Here’s a really good set of tutorials for people beginning to use quickbox2d.
|
|
|
LearningAS3
83 posts
|
Thanks for the info.
Well I can have like 50-100 enemies on screen at any given time. Is that considered “too many”?
Also I notice, in the link you provided, that shapes are majorly circle or rectangles. I dunno. Can it be done such that I can add circles in enemy classes, make them invisible. They will move whenever enemy moves, will it work and not overlap over other enemies?
|
|
|
Orangatang91
64 posts
|
Yes I think that would be too much. You can also create polygon shapes with box2d or group two or more shapes together into one. Instead of making the circles follow your enemies you are going to have to make your enemies follow the circles, check out the section in skinning. They shouldn’t overlap unless you change their default groupindex. You can easily make the circle (quickobject) invisible by using circle.userdata.visible = false; or circle.userdata.alpha = 0; but those do not need to be implemented if your are using the quickobject’s skinning property. Furthermore I am an idiot for believing that grouped objects do not automatically create a corresponding body as I have found out that they do! Mine was not working correctly because I set all the quickobjects to be static (density of zero) before grouping them. Ma baaad!
|
|
|
LearningAS3
83 posts
|
|
|
|
ErlendHL
1312 posts
|
Originally posted by LearningAS3: (I had thought of looping through all the enemies inside the enemy update function but I think it will take up too much processing power)
No way it will take too much processing power. It’s pretty much the only way to check for collision. Although you should rather have a nested loop somewhere else, so you don’t for example check enemy2 against enemy4 and later enemy4 against enemy2.
for (var i:uint = 0; i < enemies; i ++) {
for (var j:uint = i + 1; j < enemies; j++) {
This will loop through every combination only once.
|
|
|
LearningAS3
83 posts
|
Thanks.
Although I did think of looping and checking if enemies are overlapping, I am not exactly sure what I will implement once I find they are overlapping. Any suggestions?
|
|
|
ErlendHL
1312 posts
|
Originally posted by LearningAS3:
Thanks.
Although I did think of looping and checking if enemies are overlapping, I am not exactly sure what I will implement once I find they are overlapping. Any suggestions?
You can use a square hittest. Just check if the squares around two enemies are overlapping, then push the enemies away from eachother so they don’t touch if they are overlapping.
|
|
|
Lucidius
180 posts
|
If performance is an issue, or you have a ton of objects possibly colliding with one-another…Look into Rectangle.intersects(toIntersect:Rectangle) its faster than hitTest…probably the fastest collision detection with the exception of custom…also run a distance check first before testing for collision – I.E. populate an (emptied) array with potential candidates if they are close enough. Then run intersects against all of them.
Of course using Rectangle.intersects means having an instance of Rectangle for all of your objects (your enemies here) so have them create their own public Rectangle when they are created, and update its location according to their own, in their update() functions. In this way you dont have to create rectangles for objects being tested, every time they need to be tested. (some of the built in collision methods do this and its pretty inefficient obv)
|
|
|
ErlendHL
1312 posts
|
Originally posted by Lucidius:
I didn’t mean he should use the built-in hitTest function; I just used hittest as a word for checking for collision.
But using rectangle.intersect I haven’t thought about before. (I actually learned it existed some days ago).
|
|
|
LearningAS3
83 posts
|
Great advice. Thanks for it.
|