开发者

Detecting collisions and walking around objects

开发者 https://www.devze.com 2022-12-21 07:36 出处:网络
I am writing a program for an Android phone (Which uses Java as the programming language) I am writing a game that needs objects to - move around - other objects.For ex开发者_StackOverflowample:if an

I am writing a program for an Android phone (Which uses Java as the programming language)

I am writing a game that needs objects to - move around - other objects. For ex开发者_StackOverflowample: if an object was to move from point A to point B and there was another game object in the way, it would move around it.

I also need to detect collisions with object, for example if an object hits another object.

Any good resources for this stuff?


as for collision detection, theres some points you might consider according to your specific needs:

  • simplest is a bounding box collision. Every object has an invisible bounding box which you use to check if it intersects with the box of an enemy.
  • If needed you can use collections of bounding boxes to define the collision region of an object.
  • Apart from bounding boxes you could also use circle or elipse shapes
  • If you have loads and loads of objects you need some kind of partitioning scheme. If you are going to test is object A collides with all other objects it might just take too long. Simplest to do is to split your scene in a grid and in each cell only check the collisions of other objects ion this cell (and perhaps neighboring cells). More advanced ways of partitioning you might look into are quad-trees.
  • Don't use pixel perfect collision methods. Although it sounds cool, they are hardly ever useful. This is due to the fact that most probably your object will animate, and you don't want every animation frame to have different collision characteristics.


It's been a long time since I studied this, but pathfinding with potential fields might be useful.

0

精彩评论

暂无评论...
验证码 换一张
取 消