Tag Info

New answers tagged

0

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 ...


0

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, ...


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 ...


0

What you want to do is register collision callbacks for each kind of body. // You have a map from bodies to functions of bodies. Map<BodyData, Function<BodyData> > collisionCallbacks; // Invoke the function associated with that kind of body. collisionCallbacks[firstBodyUserData].Invoke(secondBodyUserData); // An example collision function void ...


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 ...


0

To keep a character level with a moving "ground" without its x position being affected by the physics engine, it would seem the best solution might be to place an SKConstraint on the character. Specifically: character.constraints = [SKConstraint.positionX(SKRange(constantValue: 0.0))] If you have any weird bugs from SpriteKit's physics engine, you might ...


0

The way I handle these kinds of 2D physics is to process the X and Y components of the vector separately. That way if a collision occurs, I know which direction the collider was moving along based on the sign and component of the velocity vector I am processing. Then when a collision occurs, you can modify the velocity on the appropriate axis. Changing 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 ...


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 ...


0

You probably should avoid sphere to intersect multiple triangles. Since you can determine time to collision for a sphere and triangle, therefore, when you detect case of multiplie collision just choose shortest time and advance your simulation for this time instead of fixed timestep. Thus you can be sure you always will deal with single collision.


0

This is not possible. Apparently, only a dynamic volume physics body can make contact with an edge body. I do not like this about Sprite Kit.


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; ...


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 ...


3

The problem I think the main flaw is that you're checking if the object is in the air using the code place_free(x, y + speedAir). That's effectively like this: Imagine your object is shaped like that blue J-tetromino and the ghost version of it represents its position + its speed; where it will be next frame. The yellow is a floor. At the first two ...


0

Great work that you are doing here :D. The thing about advanced collision detection or any technical aspect of programming is getting it done right. To do so, you must separate the mechanic you want, then make it in a separate environment, then test it then port it into your game. in this case, you want to make a separate SAT collision demo first then ...


0

How I would do it: Step 1: define rectangles for the bounds of each room and hallway. Now imagine these rectangles as safe areas where the player can be. "Out of bounds" would be declared as any position in which the player is not fully contained in any of the rooms or hallways. Here's a picture as a demonstration: Now, before we go further, you must ...


0

So, you want the angle of velocity relative to the x-axis? That'd be atan(V3.y/V3.x) and atan(V4.y/V4.x) for Q3 and Q4, respectively. Though, since the balls are almost aligned along the y-axis in relation to each other, it looks like maybe you're looking for the angle of V3/V4 relative to the surface at the point of impact, even when that doesn't line up ...


0

maby this can help you http://en.wikipedia.org/wiki/Coefficient_of_restitution there is a break down of the entire problem


1

If you have multiple sprites at the same position, are they all supposed to prevent the player from falling? if so, you can either merge them, or disable collision for one. Else, if not all the sprites should collide, maybe you can add a flag to indicate if they are ground colliders. On a side note, you could use a complete AABB instead of using arbitrary ...


0

Here is an Intersects(A,B) method implementation taken from C# Rectangle.cs public bool Intersects(Rectangle a, Rectangle b) { return (b.X < a.X + a.Width) && (a.X < (b.X + b.Width)) && (b.Y < a.Y + a.Height) && (a.Y < b.Y + b.Height); }


0

Store the x points, y points and any other polygon related data elsewhere. Then in the render function you can save the data to a local scope set of variables (or an array or List if you want) and apply the transformations using good old mathematical operators. Then you can draw the polygon using this new data.


1

If you have stacked BoxCollider2Ds like that, Unity will only capture the mouse click on the topmost one. You could: Adjust the z-layer of your colliders (I think you do this by setting the renderer's "Order in Layer"). Enable/Disable your colliders in code based on which one is on top. Do a RaycastAll, and process the click yourself.


0

you need transitional states and movement to detect what point to compare distance to. Set each point at original divide where split occurs, to a twin point at where it originally cracked apart, then always move the island based on closest twin pair. that might work, if you keep points that must match a distance condition that are corresponding points ...


0

Another way of doing it is create one island then introduce series of water splices... as a water is occupied on one side add land on another side. Terrain can be done later if you lock the boundaries of land and water as soon as you're satisfied. You can set a logic where percentage of number of island has to move greater distance than others without ...


1

I think you are going at the problem the wrong way. Why are you first building an island and then "place" it? I would use one algorithm to create the entire map in one go. Although the algorithm would need some tweaking, but I would some form of noise as the basis. From that I use a "water level" to defined how much and how large the land actually is. This ...


0

If you keep track of the position at last frame you can also create a line from last position to current position and do line to rectangle collision detection to see if you went though the terrain.


0

If you have attatched a rigidbody to your character it's likely that the collider is colliding with something in an unusual way(maybe it's stuck inside the floor) and the rigidbody spazzes out. Check if there are any other colliders next to your character's collider. Other than that, it may be a script issue. Check your OnCollision functions.


1

Making collision detection frame rate independent is basically impossible. While you can reasonably implement frame rate independent rigid body motion and many other simulations by multiplying by dt (delta time), actual collision detection is "impossible" to do frame rate independent. To illustrate the issue let us assume you have a small cube moving at a ...



Top 50 recent answers are included