Tag Info

Hot answers tagged

3

Here are the areas your nearest function associates with each tile: (assuming float % int is performed as a floating point modulo in your environment. If not, you can get broken/offset tiles instead, as visualized in the third image above) As a unit travels down and to the left, they briefly touch the stretched/offset corner of the tile below and to the ...


3

One major advantage is that many collision detection operations are more efficient when performed at the origin. A classic example is box vs sphere. When done in a box's local space the tests are very simple axis aligned distance point-plane tests instead of the more costly non-axis aligned planes. Furthermore objects moving through space may not actually ...


3

If you're using a grid, you shouldn't be using Unity's physics for collision detection - use the grid. Get your position on the grid then do something like this: public bool GridCast (Coordinate Position, Coordinate Direction, int Length) { for (int i = 0; i < Length; i++) { Coordinate Check = Position + Direction * Length; if ...


2

I had to solve this issue a long time ago, and all I did was do: One normal collision check. One where I shifted everything up one "world-height" (aka screen height) Shift down Shift left one "world-width" (screen width) Shift right Up and Right Up and Left Down and Right Down and Left eg: if(x + width > test.x && x < test.x + test.width ...


2

If you want to calculate collision really fast, and without very complex math, use bounding spheres or cubes. If you have a bounding sphere for each of the two objects, you would like to detect collision, it's really simple: Sum the radius of the two sphere, and if it's less than the distance of the two objects, then are collided, else not. Even the ...


2

Using a 2D tile array for your world/level generation and representation will definitely simplify things. For example you could internally represent your world in a grid of tiles and take it from there : using System; using System.Collections.Generic; using System.Text; namespace Tiles { public class Vector2 { public int x; public int y; ...


2

btTriangleMeshShape cannot be used as a dynamic objects as stated in the API documentation. The btBvhTriangleMeshShape is a static-triangle mesh shape, it can only be used for fixed/non-moving objects. So your alternative is to represent the mesh using Collision Primitives or a collection of them. Single Primative Using a singluar primitve is the ...


2

For arbitrary shapes The basic algorithm goes like this: // Gets the distance from a point to a shape made of line segments. float GetDistance(Shape shape, Vector2 point): min_dist = float.max; foreach LineSegment line in shape: dist = GetDistance(line, point); min_dist = min(min_dist, dist); return min_dist; // Gets the ...


2

The way I handle this is each cell has a list of entities which inhabit it and each entity has a list of cells / tiles it inhabits. This way a cell can contain multiple entities and an entity can inhabit many cells. Whenever an entity moves it checks for collisions with other entities which inhabit the cells it is moving through. Once it has finalised its ...


1

With the spatial-binning approach, there's a couple of ways to manage cell-size vs object-size. Make the cells big enough, so that cell edge >= half the biggest object, and always check adjacent cells. Check more than 1 cell away. Radius 1 checks 9 cells, radius 2 would check 25 nearby cells, and so on. Put objects "into" more than one cell. When moving, ...


1

You can try calculating the surface normal using central finite differencing, and then colliding with a locally linear plane at the collision point. Vector2 GetNormal(Grid grid, int x, int y) { float dx = grid[x + 1, y] - grid[x - 1, y]; float dy = grid[x, y + 1] - grid[x, y - 1]; return Vector2(dx * 0.5f, dy * 0.5f); } When your grid is ...


1

It's just some basic maths. There are a lot of sides and tutorials about collision detection. For example this could help: What is the fastest way to work out 2D bounding box intersection? It is really easy, as long as no box rotates. Then it is called AABB (Axis Aligned Bounding Box). It gets a little bit more complicated, if they rotate, but it's still not ...



Only top voted, non community-wiki answers of a minimum length are eligible