jPCT-AE - a 3d engine for Android > Support

How to improve the performance of collision check in a racing game?

(1/2) > >>

kiffa:
In my racing game, i used Object.checkForCollisionEllipsoid() to check collision.

The collision will happen between these objs: player's car(1 object3d)、npc-cars(1 - 6, 6 object3ds)、road-bar(one large object3d):



My codes:


--- Code: ---bar.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);

playerCar.setCollisionMode(Object3D.COLLISION_CHECK_SELF);
npcCar1.setCollisionMode(Object3D.COLLISION_CHECK_SELF);
npcCar2.setCollisionMode(Object3D.COLLISION_CHECK_SELF);
...
npcCar6.setCollisionMode(Object3D.COLLISION_CHECK_SELF);


OcTree oc = new OcTree(bar, 10, 3, OcTree.MODE_OPTIMIZED);
oc.setRenderingUse(false);
oc.setCollisionUse(true);
bar.setOcTree(oc);

//onDrawFrame
playerCar.checkForCollisionEllipsoid(step, mEllipsoid, 3);
npcCar1.checkForCollisionEllipsoid(step, mEllipsoid, 3);
...
npcCar6.checkForCollisionEllipsoid(step, mEllipsoid, 3);

--- End code ---

My question:
1, The bar has 8800 triangles, how to create the octree will give the best performance?

2, Any other suggestions to improve the collision performance? The bar is just plane.

dutch_delight:
perhaps you can only check for car to car collision when they are near you so something like this:


--- Code: ---if (playerCar.getTransformedCenter().distance(npcCar1.getTransformedCenter()) < 100) {
npcCar1.checkForCollisionEllipsoid(step, mEllipsoid, 3);
}
--- End code ---

dont know if that will be quicker but that's what i do. i only do important calculations on the ai cars when the player can actually see them close enough.

as for the bar, cant you optimize that somehow? 8800 triangles seems a bit high for a collision mesh

EgonOlsen:
~8000 polygons for a collision mesh is fine if you are using an octree. Something around 500 polygons per leaf should do it. For reference: The landscape in my RPG game uses around 8000 polygons and an octree with 500 polygons per leaf and it works fine even on older devices. Just make sure that you are using it for collision detection only, because using it for rendering might be slower than simply rendering the mesh at once.

kiffa:
To dutch_delight:
  Thanks for your advice.
  And in your game, how do you implement the AI? I was bothered by AI these days, i didn't use the waypoints, i just let them run, then check collision, then move by the result of  checkForCollisionEllipsoid(). Codes:
 
--- Code: ---SimpleVector step = calcStepBySpeed(deltaTime);
  step = npcCar.checkForCollisionEllipsoid(step, mEllipsoid, 3);
  step.y = 0; // flat road, no up an downs.
  npcCar.translate(step);
--- End code ---
  I think this is a rather bad AI :-\ , and i need  check collision every frame. If you would share your design, there will be many thanks.

To EgonOlsen:
  What dose the return value of checkForCollisionEllipsoid() accurately mean? Does the return vector has the same length as the origin vector? Could you explain the algorithm? Could i use obb instead of ellipsoid in jPCT-AE? Which is more suitable for my game?


And there are 7 cars in my game(1player + 6 npc), so there are 7 checkForCollisionEllipsoid() calls per frame, i think this is expensive, any suggestions?

EgonOlsen:

--- Quote from: kiffa on April 19, 2013, 05:03:03 am ---What dose the return value of checkForCollisionEllipsoid() accurately mean?

--- End quote ---

It's the corrected translation vector. It can have any lenght but it won't be larger than the initial translation. It's the translation to apply to the object to avoid a collision while sliding along the obstacle.


--- Quote from: kiffa on April 19, 2013, 05:03:03 am ---And there are 7 cars in my game(1player + 6 npc), so there are 7 checkForCollisionEllipsoid() calls per frame, i think this is expensive, any suggestions?

--- End quote ---

If they interact with each other only, then this shouldn't be a problem. If they all are supposed to collide with the track's borders, then it might become one. All i can say is: Be creative. The build-in collision detection method smight not be the best ones to choose for a car racing game. You could, for example, simplify your car checks to simple 2d box checks, which might be better to handle car physics anyway.

Navigation

[0] Message Index

[#] Next page

Go to full version