Tag Info

New answers tagged

0

Before I answer this question here's a quick idea of how I would go about implementing an infinite or endless runner. I have worked on a couple of endless runners and they have both worked in the same way. This isn't necessarily the only way to do it but it is a way that has been proven to work. You can create generic sections of a level that contain ...


1

Vector math are really essential to detect proper collisions and the information to resolve it the properly. But its not that hard really: Just 4 things you need to know about vectors to get started: Its just basic addition, subtraction, multiplication with the concept of doing it on "multiple" components at once (X, Y, Z in 3D and X, Y in 2D) - but each ...


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


0

Sphere collision is definitely the easiest to implement. Simply do distance checks between 2 objects. I.e.: if ((ObjectA.Position - ObjectB.Position).magnitude > ObjectA.Radius + ObjectB.Radius) { //Collision } For walls, you can use axis-aligned bounding boxes. For a sphere object, its bounding box min/max is its position added or subtracted its ...


0

First of all you should use a DebugRenderer for testing your Box2D world. Otherwise you will have a hard time figuring out what your world is actually doing: Box2DDebugRenderer debugRenderer = new Box2DDebugRenderer(); //the below code goes at the end of the render method: debugRenderer.render(world, camera.combined); Then another thing that catched my ...


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


0

It kinda depends on what you're making. If you're making a game about physics, you could conceivably write your own physics engine, however I do not recommend it. There are many 2D and 3D physics engines already out there that you can use that will save you months of work. My first time using Box2d was intimidating, and I'll admit it has a fair learning ...


0

This is what I use to check collision between circle / rectangle. Note that this doesn't do continuous collision detection. Which means that if both of the shapes are unproportionally small or the objects are colliding with really high speeds (because you have too low fps and you use Delta Time to calculate the velocity for example), then the collision ...


0

Unity 5 adds the PlatformEffector2D component, which I think solves this same question. If you add a collider and attach it to this effector, you should be able to create the one-way platform with less fuss, which would simplify the code for dropping down, as well.


0

As it is said, you should make one post per question. You can use a circle collider instead of a rectangle collider. Set the circle radius by experimentation. You can also implement a combination of both, if you care about extreme precision, but a circle should be enough for your purposes.


0

I'm not sure if you're speaking of inability to keep up with FPS or UPS (Updates Per Seconds), but if machine has lower frames per second than expected you shouldn't change rate at which you're logic is being updated (UPS). Content of window is drawn depending on machine's capabilities but logic (and physics) run at constant and independent rate. In this ...


0

Like both answers said, there are 2 "secrets", one is you need to stop applying gravity when bounces are determined to be over (which is a bit of an extension over Leftium answers, he just said "resting" which is not enough because you rest as soon as you touch by this definition). Secondly, check for speed, obviously. This later condition is in relation to ...


0

Stop applying (the gravity) force after reaching RESTING_CONTACT. My guess is your sphere is reaching resting contact, but gravity (or other forces) causes it to continue moving as soon as the next update happens. Explanation: Generally, once an object reaches resting contact, it should not respond to forces until there is a force large enough to "push" ...


0

If I understand your question correctly, you are trying to find the center of the hex cell to which an arbitrary point belongs. Your question made me think of Voronoi diagrams... I have a gut feeling that they might be relevant here, though other solutions might have a better performance. (This solution might be wrong too, but I feel like it could be ...


0

I'm not totally sure I understand your question. You are having trouble converting a position into a hexagon coordinate? If so I did some research on turning a vector position into a hexagon coordinate that might help you out. But first of all I highly recommend this website for general hexagon coordinate information: ...


0

The problem is a typical starters error: you chose both loops iteration variable to be the same, so they modify each other. You should always choose nested loops to use a different iteration variable(usually called i, j, k), otherwise things will get messed up. In other languages completely, but here you got the two objects already and using the keys only ...


0

Instead of checking the distance for a resting contact, check for velocity. If 2 objects are moving slowly and hit each other, they should be put to rest. If not, they should do what they would do if they weren't resting. So... if (CollisionDetection()) { if (sphereVelocity.GetMagnitude() <= .1f) { //NoGravity(); //NoForces(); ...


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

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


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.



Top 50 recent answers are included