Dodge different type of obstacles I'm writing a 2D game where the player has to kill a Ninja. This Ninja is coming closer with a constant speed chasing the player. The Map has some static obstacles like stones no one can pass. The player can move too and has different types of weapons to damage the Ninja in different ways Laser instantly on whole range Gun projectile (circular) following a fixed path Trap circular floor ability which detonates after time I want the Ninja to dodge those Weapons the best he can, he is allowed to take some damage, the least is preferred. I now have different ideas how to achieve that A with 3rd dimension (time) This is working but the paths are ugly and post processing is not my favorite. Also the Graph's size is about 1000x1000, making it inefficient (on creating neighbors), i try to reduce node count by scaling the nodes to unit.hitbox (40px), which drastically improves the calcs, but the paths look even more ugly.. Theta won't work even tho I love it, but line of sight on moving obstacles is... Visibility Graph same as Theta , moving obstacles... Steering haven't tried this one yet how it performs with constant speed and moving (, delayed) obstacles Local Avoidance won't work as the weapon speed is bigger than Ninja movement speed Geometry tangents, vector projection etc.... could work well if there aren't much obstacles to dodge Do you have any other ideas how to achieve some good doing for the poor Ninja? (NINJAS USUALLY DODGE EVERYTHING... That's why I also plan to give the Ninja a Ninja Roll feature he can use every 10s to dash on some position if he can't dodge something) Representation of the raw map (little dots are 40px) A Pathfinding with time dimension and a 5px Grid Edit I'll check out D Lite and RRT Smart Edit 2 Both are not what im looking for, i will try to optimize A


C Monogame Collision Detection Sprite walking through platforms I am blanking on the logic here. How do I get it so that my sprite doesn't run through a block. It only repels if the center of the player sprite is higher than the bottom of the block. But when it is lower, it walks right through. It gets lower because my jump function or my grounded function is a bit funky. Anyway, how do I get it so that a player can't go underneath a block unless the sprite is not touching the block at all. Here is the collision code in my player class, the one that does the collision detection. public void checkYCollisions(block platforms) if (position.Y gt 700) this is my ground with no blocks. grounded true else grounded false float Xradius Width 2 float Yradius Height 2 block collidedPlatform null List lt block gt collidedBlocks new List lt block gt () foreach (block p in platforms) if ((position.X gt (p.position.X p.Width 2 Xradius )) amp amp (position.X lt (p.position.X p.Width 2 Xradius )) amp amp (position.Y gt (p.position.Y p.Height 2 Yradius )) amp amp on top (position.Y lt (p.position.Y p.Height 2 Yradius ))) below collidedBlocks.Add(p) collisions work for all side of blocks. foreach (block p in collidedBlocks) if (p ! null) if ((position.Y lt (p.position.Y p.Height 2 radius ))) landing on a block grounded true else if ((position.Y gt (p.position.Y p.Height 2 Yradius ))) jumping up into a block if (y vel lt 0) y vel 1 player1.direction.Y 1.0f player1.direction.Y else if ((position.X lt (p.position.X p.Width 1.5 Xradius ))) one of the sides x vel 2 else if ((position.X gt (p.position.X p.Width 1.5 Xradius ))) other side x vel 2 Note that I have tried to remove YRadius in the the if loops at separate occurences, and it works to no avail because my guy will not hit the ceiling.


Swept AABB vs Line Segment 2D I've really exhausted as much as Google has to give, I've spent a solid week googling every combination of words for an "AABBvsLine sweep", downloaded countless collision demos, dissected SAT intersection examples and an AABBvsAABB sweep trying to figure out how to approach this. I've not found a single thing covering this specific pairing. Can anyone shed any light on how to get the hit time of a swept AABB vs a Line segment in 2D? I'm still getting familiar with the SAT but I do know how to implement it to a degree, I'm just not sure how to extract the hit time from the velocity in the non axis aligned separating axes for the sweep. I really would appreciate anything at the moment, some code or even some helpful links, I'm at my wits end!


How do physics engines like Box2D detect and respond to collisions between arbitrary polygons? I've always wondered how collision detection like this was achieved, and I've always wondered what the response would be. Do they perform line line intersection tests for each line making up the two polygons? If it'd make the question any more specific, how does Box2D handle this?


Determining which line to collide with I am making a platformer, where my player is represented as a circle and the ground is represented as lines. The actual collision detection and resolving works, it's just an edge case I can't find a solution for. I check on which line the hero is by using the normal, and if the hero's center is between these normals I know he is on that line. That works except for the case in the image above. When he get's in the 'Problematic Area' the algorithm will not detect any collision. So how do I know which line to pick for the collision when the hero get's in this area? Here is some code that shows how I test collisions (which again works, but does not consider the problem I actually have). playerPointer Vector2D New Vector2D(position.x line.x1, position.y line.y1) lineNormal Vector2D line.vector.Copy() lineNormal.LeftHandNormal() playerOnNormal Float playerPointer.ProjectionOn(lineNormal) playerOnLine Float playerPointer.ProjectionOn(line.vector) Do we have a collision between the circle and the infinite line If Abs(playerOnNormal) lt radius Get the direction vector of the line Local directionVector New Vector2D(line.x2 line.x1, line.y2 line.y1) Is the player inside the normals boundaries If (playerOnLine lt directionVector.Length) And (playerOnLine gt 0)


Implementing Separating Axis Theorem (SAT) and Minimum Translation Vector (MTV) I was following codezealot's tutorial on SAT and MTV and trying to implement it myself but I've come a cropper when it comes to getting the correct MTV. Here is my example (Cue pretty pictures...) I'm well aware how to obtain the length of the MTV and the axis on which it lies. However I can't work out whether the length should be 'positive' or 'negative' to push the object in the correct direction. In the example we are separating the objects by moving the 'red' of the 'blue', the top example is moving the object negatively and the bottom moving it positively. Please help I'm really struggling with this. Here is my actual implementation.


Unreal Engine 4.18 Knife (Weapon) collides with character capsule collision I have a character and he has a knife in his hand. When Run Walk action happens hands move and so does knife, its collision collides with character's capsule collision and causes issue in movement. More info Component Hierarchy looks like


Super mario bros "rounded" tile collision detection I'm working on a Mario bros clone with SDL and C (purely for educational porpuses and for fun) I got collision detection working by using AABB collision detection and resolving one axis at a time Check collision with X axis first Move entity if not collision is detected Check collision with the Y axis. Move entity if not collision is detected This is working great! However, one thing that I really like about the original Mario bros is that tiles have some kind of "rounded" feel to them. I think this helps make the map feel more organic, see how Mario moves left when jumping on a corner in the original SNES game I thought of using a circle collider for mario instead of an AABB. This would make Mario "fall" off the tiles if you step too close to the edges. But perhaps someone knows a better approach. I've been thinking about collision detection for longer than I'd like to admit. I'd love to know if someone has a clean aproach to accomplish what the GIF shows.


How to manage collision between balls in Game Maker 2 (Drag and Drop) Hey there I'm using Game Maker 2 Drag and Drop for a project, I made a game like Break Out and when the ball collides with the wall it doesn't bounce, in Game Maker Studio we had Bounce Action but in GMS2 is deleted, can anyone help me about this issue?


Intersection of thick line with a grid There is a popular paper, and numerous examples, on how to efficiently perform collision detection for a line with a grid. However, I'm drawing up blanks on how to do the same thing but with a line that has thickness. In my game, I'm considering adding projectiles that are not infinitly thin (for example, a giant plasma ball launcher), and I need to figure out which cells along a grid that it collides with. Initially I thought it'd be as simple as just using the Minkowski Sum method of adding the width height of the projectile to each cell of the grid, and then treating the projectile as infinity thin line along a bloated overlapping grid, but that doesn't look like it's going to work with the existing algorithm. Are there any other papers algorithms that describe how to accomplish this? Or is there a way to modify the existing algorithm to accomplish this? Or are there any tricks to implementing this indirectly?


Adding Leniency to Jumping Mechanic I have written some jumping code for my player in a platformer game. At the moment it has some basic logic which says that the player can jump if he is on the ground. The pseudocode looks something like this Input Handling if(jumpButtonPressed) if(onGround) jump Player Update Loop onGround false movePlayer resolveCollisions if(player collided with ground) onGround true This works fine for basic static tile levels, but when the player is standing on a descending platform, or moving down a downward slope for instance, it becomes very difficult to jump. The reason for this (in the case of the descending platform) is that the platform has moved from underneath him in that frame, so for that moment he is not actually colliding with the ground, and therefore the condition to be able to jump is not fulfilled. Is there a general way to add some leniency into the jump mechanic so that the player can jump even if they are not technically on the ground for that exact frame? This seems like it should be quite a common problem but I cannot seem to find any similar questions on stackexchange or google.


Collision detected at different times depending on speed? Imagine a scenario where there are four cubes. Two blacks that do not move, one red moving at a constant speed of two (2) straight and the other blue moving at a constant speed of five (5) also straight. They all have equal bounding boxes. By doing a test, I realized that if I put a command so that as soon as the red cube strikes against the black it turns left, the command does not run as soon as they collide ... With the blue he wanted him to turn right as soon as he hit. The command takes longer to happen, I think because it is faster than red ... Illustration of the incident It seems that the faster the object is, the longer it responds to the collision command. I would like you to give me a solution to this problem. I've already moved with some bounding box options, but nothing that has given the desired result. I also moved at the speed of the room, but it did not work either. Sorry for any translation error. Thanks in advance!


Directional, Triangular Collision Detection in Pygame I am trying to create a game in Pygame, with Python 3, and am trying to figure out an algorithm that will tell me which direction a rectangle is colliding with a rectangle, so that I can push it back the correct direction. I know I can detect rect to rect, and I could (possibly?) use pixel to pixel collision, but I was wondering if there was a better way. My collision algorithm currently loops through all of the "entity" objects in a Pygame sprite.Group(), and testing for collision using the colliderect() method, then I test which direction the rect is coming from by testing which sides overlap. Is there something similar that I could do with a collision between a triangle and a rectangle, too? Pseudocode would be nice.


3D collision detection middleware (I've split this question into two. For 2D, see 2D collision detection middleware) Are there any recommendable middleware available for 3D collision detection? I believe I've heard Bullet has a pretty good 3D collision detection that can be used without the physics engine. I'd like to hear if people have any experiences on Bullet or other libraries for 3D collision detection specifically.


What's the fastest collision detection (Game Maker) I want to build a simulator using Game Maker in which there are many (up to hundreds) of obj Cell, each has a radius of 10, (they don't have sprites, they just draw a circle with radius 10). Each step, I want the cells to check around itself for obj A to see if any obj A is "touching" it, (has a distance less than 10 from the cell). However, since I have so many obj Cell and so many obj A, the most straight forward code (below) will have to be executed tens of thousands of times (number of obj A number of obj Cell) In obj Cell (with obj A) if distance to object(other) lt 10 do stuff Is there any possible way to make this faster?


AABB test does not consistently detect edge to edge contact when bounds are very different in size My function compares two AABBs for collision detection, and when they are around the same size it works fine, but I noticed that if I greatly decreased the size of one of them (or augmented the size of the other), then the collision wouldn't be detected correctly I would have to have them intersect for a collision to be registered, rather than having it register when they are at least in direct contact, which is the intended behavior. Below is my code local function DetectCollision(a, b) AABB to AABB local collisionX (a.Position.X a.Size.X) gt b.Position.X and (b.Position.X b.Size.X) gt a.Position.X local collisionY (a.Position.Y a.Size.Y) gt b.Position.Y and (b.Position.Y b.Size.Y) gt a.Position.Y local collisionZ (a.Position.Z a.Size.Z) gt b.Position.Z and (b.Position.Z b.Size.Z) gt a.Position.Z return collisionX and collisionY and collisionZ end To be more specific, the issues start to occur when I cut the size of one of the AABBs in half. For instance, if I had two cubes where one's size is 12 on all axes and the other is 6 on all axes, then the collision will not register. Upon debugging, I noticed that only one of the collision bools will become false. This seems to depend on what axis the smaller bounding box moves from in relation to the bigger one, so if I moved the smaller AABB away from the bigger one on the y axis, then collisionY will be false.


One SKSpriteNode with multiple PhysicsBodies? I am making a game similar to Lunar Lander, when you land with your ship on different objects, etc... The issue I am having is that I have a Player SKSpriteNode (my Ship) with a slightly complex collision system (bottom of the ship has different CategoryBitMask from other sides, etc.) and when I apply PhysicsBody(bodies physicsBodiesArray ) I cannot control CategoryBitMask for each element of the physicsBodiesArray ... Because main PhysicsBody is applied to the Player it overrides all other Categories and such. Here is my "createPlayer" function Creating the player player SKSpriteNode(imageNamed "Bottle 02") player.size CGSize(width 130, height 200) player.position CGPoint(x 0, y 0 player.frame.height 2) Creating 2 collision objects and placing them var playerColTop SKSpriteNode() var playerColBottom SKSpriteNode() playerColTop SKSpriteNode(imageNamed "test top") playerColBottom SKSpriteNode(imageNamed "test bottom") playerColTop.position CGPoint(x 0.5, y 0) playerColBottom.position CGPoint(x 0.5, y 0 playerColTop.frame.height 2 playerColBottom.frame.height 2) Creating PhysicsBodies for the Array and assigning CategoryBitMasks let playerColTopPhys SKPhysicsBody(texture playerColTop.texture!, size playerColTop.size) let playerColBottomPhys SKPhysicsBody(texture playerColBottom.texture!, size playerColBottom.size) playerColTopPhys.categoryBitMask PhysicsParams.Player playerColTopPhys.collisionBitMask PhysicsParams.Ground PhysicsParams.Walls playerColTopPhys.contactTestBitMask PhysicsParams.Ground PhysicsParams.Walls playerColBottomPhys.categoryBitMask PhysicsParams.PlayerScore playerColBottomPhys.collisionBitMask PhysicsParams.Ground PhysicsParams.Walls playerColBottomPhys.contactTestBitMask PhysicsParams.Ground PhysicsParams.Walls Adding my PhysicsBodies and setting up the Player player.physicsBody SKPhysicsBody.init(bodies playerColTopPhys, playerColBottomPhys ) player.physicsBody?.categoryBitMask PhysicsParams.Player player.physicsBody?.collisionBitMask PhysicsParams.Ground PhysicsParams.Walls player.physicsBody?.contactTestBitMask PhysicsParams.Ground PhysicsParams.Walls player.physicsBody?.restitution 0 player.physicsBody?.friction 1 player.physicsBody?.mass 5 player.physicsBody?.affectedByGravity false player.physicsBody?.isDynamic false self.addChild(player) Thanks in advance!


Game Maker 8.0 Can I simulate any collision event within the step event of an object including the "other" reference? Let's say I have two objects. One is "obj wall" and the other is "obj player". For the sake of argument, let us assume that I cannot just add a collision event to obj wall (I truly cannot due to limitations embedded within the nature of the project itself). Is there a function or block that allows one to write a collision event within obj wall's step event? I know there are various collision detection functions, but what I need is one that acts identically to the collision event and allows me to access the "other" property. If this is not possible, are there any suitable alternatives (such as a function that detects collision and returns the instance id of an object colliding the wall)? My primary issue here is that I want to be able to use collision in one instance of an object without having to have the collision event added. I'd prefer it to be as close as possible to the collision event so as to avoid unnecessary extra checks.


How do I determine wall direction, with information of normal and incoming direction? What is formula and theorys used to determine wall direction, with only knowing the normal of the wall and the direction of the incoming object? This answer has already stated a formula, but I don't know where it came from, and I am in need of understanding.


Collision detection in multiplayer games This a followup to my previous question How to implement physics and AoE spells in an MMO game?. There, we concluded that all physics have to be done on the server, and that I should use cylinders for calculations. Now, how can I check for collision detection on a ground to player basis on the server? It's fairly easy if the ground is a flat space, I just check if the player's z coordinate is lower than some value and voila, but, what if the map ground itself is a model? How do I know where hills are on the server side? How do I know when object collisions happen? I'm using node.js and socket.io.


What type of Collider should I add to a LineRenderer? I am currently building a game where I need to generate some wires (as B zier curves) using LineRenderer. After changing the width of each line lineRenderer.SetWidth (0.15f, 0.15f) I am attaching an EdgeCollider2D to the same game object (specifying the same points used in generating the B zier curve). This seems to work. However, I would like to be able to know if the Mouse Pointer is at any time over the EdgeCollider2D (something similar to the popular Fruit Ninja game). I'm using Raycast as follows void CastRay() Ray ray Camera.main.ScreenPointToRay (Input.mousePosition) RaycastHit2D hit Physics2D.Raycast (ray.origin, ray.direction, Mathf.Infinity) if (hit) Debug.Log (hit.collider.gameObject.name) I'm calling the CastRay method inside the Update method. Because EdgeCollider2D does not have width (as expected), the log message is never produced. Do I need to use a different type of Collider? Do I need to call CastRay somewhere else?


Collision resolution when moving in two directions I am making a bomberman clone and I'm having problems regarding moving on both x and y axis (pressing down left, down right, up left). Here is a video to demonstrate the problem. I use Tiled for the map. Below is the code private void checkCollision(float delta) player.getVelocity().scl(delta) dont mind Vector2 position player.getPosition() if(player.isMovingRight()) Array lt Rectangle gt tiles getTiles((int)(position.x TILE SIZE 1), (int)(position.y TILE SIZE 1), (int)(position.x TILE SIZE 1), (int)(position.y TILE SIZE 1)) for (Rectangle tile tiles) if(player.getRectangle().overlaps(tile)) System.out.println("overlap right") player.setPosition(tile.x player.getWidth() , player.getPosition().y) if(player.isMovingLeft()) Array lt Rectangle gt tiles getTiles((int)(position.x TILE SIZE 1), (int)(position.y TILE SIZE 1), (int)(position.x TILE SIZE 1), (int)(position.y TILE SIZE 1)) for (Rectangle tile tiles) if(player.getRectangle().overlaps(tile)) System.out.println("overlap left") player.setPosition(tile.x tile.width, player.getPosition().y) if(player.isMovingUp()) Array lt Rectangle gt tiles getTiles((int)(position.x TILE SIZE 1), (int)(position.y TILE SIZE 1), (int)(position.x TILE SIZE 1), (int)(position.y TILE SIZE)) for (Rectangle tile tiles) if(player.getRectangle().overlaps(tile)) System.out.println("overlap up") player.setPosition(player.getPosition().x, tile.y tile.height) if(player.isMovingDown()) Array lt Rectangle gt tiles getTiles((int)(position.x TILE SIZE 1), (int)(position.y TILE SIZE 1), (int)(position.x TILE SIZE 1), (int)(position.y TILE SIZE 1)) for (Rectangle tile tiles) if(player.getRectangle().overlaps(tile)) System.out.println("overlap down") player.setPosition(player.getPosition().x, tile.y player.getHeight()) player.getVelocity().scl(1 delta) private Array lt Rectangle gt getTiles(int startX, int startY, int endX, int endY) TiledMapTileLayer layer (TiledMapTileLayer)level.getMap().getLayers().get(1) Array lt Rectangle gt rectangles new Array lt Rectangle gt () for (int x startX x lt endX x ) for (int y startY y lt endY y ) Cell cell layer.getCell(x, y) if(cell ! null) Rectangle rect new Rectangle(x TILE SIZE, y TILE SIZE, TILE SIZE, TILE SIZE) rectangles.add(rect) return rectangles To reproduce the problem shown in the video Try to collide (coming from up) with one of the blocks that is not on the sides, press both down and left. Try again but press down and right. For the third one, make sure you are colliding with the top wall by pressing up then press left (both are pressed). It can also be done on the bottom wall by pressing down and left.


Am I implimenting a sweep and prune broadphase correctly? The code that I am using is std vector lt PhysicsBody gt physicsChildren containing all objects ... std sort(physicsChildren.begin(), physicsChildren.end(), sortByLeft) std vector lt PhysicsBody gt activeList unsigned int one unsigned int two for(one 0 one lt physicsChildren.size() one) activeList.push back(physicsChildren one ) for(two 0 two lt activeList.size() two) if (physicsChildren one gt m position.x physicsChildren one gt m radius gt activeList two gt m position.x activeList two gt m radius) CheckIntersectionBetween(physicsChildren one , activeList two ) else activeList.pop back() I think something is wrong because for 800 objects 309169 calls to CheckIntersectionBetween. A bruteforce would use 640000 calls, I didn't think this was much improvement (considering only objects close in the x axis should test). I wrote the code from reading Jitter Physics article about SAP Create a new temporary list called activeList . You begin on the left of your axisList, adding the first item to the activeList. Now you have a look at the next item in the axisList and compare it with all items currently in the activeList (at the moment just one) If the new item s left is greater then the current activeList item right, then remove the activeList item from the activeList otherwise report a possible collision between the new axisList item and the current activeList item. Add the new item itself to the activeList and continue with the next item in the axisList. What have I done wrong?


What are the technologies that makes physics engines so good for raycasting? again. This question is strictly related to this one so, what is the technology that makes physics engines suitable for raycasting? It is a particular data structure? Has it to do with the engine's internal representation of the objects? If so, how do they represent objects so to be able to make polygon precise raycasting? Do they hold the whole information about a mesh?


player teleporting into other levels So I basically want to load another map once the player collides with a object, specifically a quot Portal quot in my game. Which is really making the player move onto other levels. I don't want to jumble up my code with a bunch of function like quot go to level 9 quot or something so I'm planning to use a list or dictionary or something. So how to those game devs out there do that? Code for main.py is here https pastebin.com rpddq1MP. The part with the portal stuff, walls and a few others for tile object in self.map.tmxdata.objects obj center vec(tile object.x tile object.width 2, tile object.y tile object.height 2) if tile object.name 'player' self.player Player(self, obj center.x, obj center.y) if tile object.name 'zombie' Mob(self, obj center.x, obj center.y) if tile object.name ' ' Obstacle(self, tile object.x, tile object.y, tile object.width, tile object.height) if tile object.name in 'health', 'shotgun' Item(self, obj center, tile object.name) if tile object.name 'portal' self.map TiledMap(path.join(self.map folder, tile object.type)) how do you do it? I'm currently using Tiled and pygame so I'm also using pytmx. Edit When I run the code, it just gives me an error about my other file, tilemap.py. Error File quot D coding my coding stuff python games pygames little rpg tilemap.py quot , line 49, in apply return entity.rect.move(self.camera.topleft) AttributeError 'TiledMap' object has no attribute 'rect' Tilemap.py import pygame as pg import pytmx from settings import def collide hit rect(one, two) return one.hit rect.colliderect(two.rect) class Map def init (self, filename) self.data with open(filename, 'rt') as f for line in f self.data.append(line.strip()) self.tilewidth len(self.data 0 ) self.tileheight len(self.data) self.width self.tilewidth TILESIZE self.height self.tileheight TILESIZE class TiledMap def init (self, filename) tm pytmx.load pygame(filename, pixelalpha True) self.width tm.width tm.tilewidth self.height tm.height tm.tileheight self.tmxdata tm def render(self, surface) ti self.tmxdata.get tile image by gid for layer in self.tmxdata.visible layers if isinstance(layer, pytmx.TiledTileLayer) for x, y, gid, in layer tile ti(gid) if tile surface.blit(tile, (x self.tmxdata.tilewidth, y self.tmxdata.tileheight)) def make map(self) temp surface pg.Surface((self.width, self.height)) self.render(temp surface) return temp surface class Camera def init (self, width, height) self.camera pg.Rect(0, 0, width, height) self.width width self.height height def apply(self, entity) return entity.rect.move(self.camera.topleft) def apply rect(self, rect) return rect.move(self.camera.topleft) def update(self, target) x target.rect.centerx int(WIDTH 2) y target.rect.centery int(HEIGHT 2) limit scrolling to map size x min(0, x) left y min(0, y) top x max( (self.width WIDTH), x) right y max( (self.height HEIGHT), y) bottom self.camera pg.Rect(x, y, self.width, self.height)


Simple Bounding Box Multiple Collision problem I'm making my first game, and in it I use a moving ball to hit static blocks (kinda like breakout). Basically, I loop through all of the static blocks on the screen each frame, update the position of the ball based on its velocity, and if it collides with a block, the ball will bounce back off of the block. If the ball hits one block exactly, then there is no problem whatsoever. But if the ball happens to hit two blocks at the same time (that is, it hits in between both blocks), it passes right through both of them no deflection whatsoever. (I know the looping is inefficient and I'm looking to correct that later, but if it has to do with the problem, I just hope someone can point to me why it is that the collision resolution fails when two similar objects are hit at once.)


HTML5 platformer collision detection problem I'm working on a 2D platformer game, and I'm having a lot of trouble with collision detection. I've looked trough some tutorials, questions asked here and Stackoverflow, but I guess I'm just too dumb to understand what's wrong with my code. I've wanted to make simple bounding box style collisions and ability to determine on which side of the box the collision happens, but no matter what I do, I always get some weird glitches, like the player gets stuck on the wall or the jumping is jittery. You can test the game here Platform engine test. Arrow keys move and z run, x jump, c shoot. Try to jump into the first pit and slide on the wall. Here's the collision detection code function checkCollisions(a, b) if ((a.x gt b.x b.width) (a.x a.width lt b.x) (a.y gt b.y b.height) (a.y a.height lt b.y)) return false else handleCollisions(a, b) return true function handleCollisions(a, b) var a top a.y, a bottom a.y a.height, a left a.x, a right a.x a.width, b top b.y, b bottom b.y b.height, b left b.x, b right b.x b.width if (a bottom a.vy gt b top amp amp distanceBetween(a bottom, b top) a.vy lt distanceBetween(a bottom, b bottom)) a.topCollision true a.y b.y a.height 2 a.vy 0 a.canJump true else if (a top a.vy lt b bottom amp amp distanceBetween(a top, b bottom) a.vy lt distanceBetween(a top, b top)) a.bottomCollision true a.y b.y b.height a.vy 0 else if (a right a.vx gt b left amp amp distanceBetween(a right, b left) lt distanceBetween(a right, b right)) a.rightCollision true a.x b.x a.width 3 a.vx 0 else if (a left a.vx lt b right amp amp distanceBetween(a left, b right) lt distanceBetween(a left, b left)) a.leftCollision true a.x b.x b.width 3 a.vx 0 function distanceBetween(a, b) return Math.abs(b a)


Box collisions between vehicles in traffic pattern I'm working on a traffic simulator. Right now, I have ways to manage 4 way stop intersections and a solution for efficiently determining which vehicles are colliding with one another. All vehicles operate independently of each other and will overlap ignore any vehicles they pass. I'm looking to build a way to resolve collisions between vehicles such that a Vehicle will follow the Vehicle in front of it. If a Vehicle stops at an intersection, any Vehicles that follow thereafter should stop and wait as well. Below are the relevant components I already implemented TileGrid containing road segments. TravelGraph graph of waypoints for Vehicles to travel along the TileGrid. CollisionTracker for efficiently determining which vehicles are colliding, i.e. O(1) lookup for get collisions( lt vehicle id gt ) gt List lt vehicle ids gt Intersection for determining which vehicles are waiting at an intersection and determining which Vehicles may pass through it. The only seemingly viable algorithm right now is Calculate velocities and position of all vehicles after tick Determine which vehicles are in a collision Determine which vehicles are in a "collision group" (e.g. if A collides with B, collides with C, then (A, B, C) are in a group) Determine the order of the vehicles in each group based on their velocities (e.g. if A, B, and C are moving to the right and C is the rightmost, followed by B, followed by A, then the order is C, B, A ). Recalculate the positions of all vehicles, in order from front to back (e.g. C, B, A) such that they reside adjacent to, but not touching the Vehicle in front of them. Problems with this solution This requires a lot of recalculations. If there's a line of n vehicles waiting on a light, I'd effectively compute 2 n positions per tick in addition to all other overhead for establishing groups, order, etc. If the vehicles are following each other around a turn, the logic for finding the "vehicle order" becomes more complex, adding on to the computations per tick. Ideally moving the vehicles would require n calculations per tick. I'm open to any all suggestions here. I've tried building my code as modular as possible, so I'll happily rewrite large parts of it if there's a better architecture to solve this problem. Below is the visual representation of the TileGrid (black), TileGraph (purple), and Vehicles (circles).


Gravity and collision detection interfering with player movement I am attempting to implement collision detection for a 2d sidescroller game and I'm having trouble keeping gravity from interfering with player movement. Every frame I get and handle input, creating values for a point that represents the players movement vector. I then add gravity to the vector and check for collisions. This is the way AI will be handled as well. The problem I'm having is when the player is on a floor tile, even if the input says to walk horizontally, after I add gravity to the move vector, collision detection returns a collision so the movement is completely negated. I know i can test which a is is the problem, negate that and move the player but then if I change the players movement vector inside collision testing, wouldn't I have to cull for collisions again based off the new move vector? I don't know if this has to do with input handling or collision testing. So how should I go about adding gravity to the players movement?


Ways to define a curve I'm trying to give shapes in my physics engine roundness curvature. I am aware of various methods for mathematically defining curves such as bezier cruves, ellipses, etc. However I am not sure which methods would be most appropriate for use in my physics engine, because speed, feasibility of construction, and flexibility of each method must be considered. I want a system in which a user can easily form fairly complex curves, but still make the intersection calculations simple and fast. My physics engine is also purely continuous, which means I must be able to calculate the time in which curves will collide with other curves and lines based on a constant linear angular velocity. What techniques are there for mathematically defining a 2D curve? What are the advantages disatvantages of each in terms of speed, flexibility, and simplicity of construction? Is the technique feasible for an engine where predictability of shape intersection is crucial?


given the position and velocity of an object how can I detect possible Collision? I'm trying to detect Collision between autonomous moving objects and steer direction if collision is detected. so far I've been following a tutorial and I'm having a hard time to fully understand how it works especially the role of the dot product foreach (GameObject t in targets) get me all moving agents Vector3 relativePos Agent targetAgent t.GetComponent lt Agent gt () access properties like velocity relativePos t.transform.position transform.position Vector3 relativeVel targetAgent.velocity agent.velocity float relativeSpeed relativeVel.magnitude can someone explain this part of code how did we calculate the time of collision? float timeToCollision Vector3.Dot(relativePos, relativeVel) timeToCollision relativeSpeed relativeSpeed 1 float distance relativePos.magnitude float minSeparation distance relativeSpeed timeToCollision


Collision detection in Arkanoid like game at intersections I'm creating an Arkanoid like game from scratch. I have no (formal or informal) education of any kind in game development, so I kinda made up things as I went regarding collision detection based on personal ideas of "how it probably works". I approximate the ball as a point and ignore its thickness, which is small anyway. I compensate for this visually by very slightly making all objects smaller than they are. I don't "detect" collision, but anticipate it and change the outcome of the next frame. For example The ball is currently in position A, and it "wants" to go to E (red line). But I calculate all intersections with all segments which make up the bricks B, C, D. The closest one to starting point (A) is B, so I choose B as the "real" intersection. I destroy the brick this segment belongs to. Now I check how would the ball proceed if it would start at B, with its vector flipped horizontally (because I determine that the segment it hit was horizontal). This is the blue line. Again, from F and G, I pick F. I destroy the brick this segment belongs to. Lastly, the orange line doesn't intersect, so I determine that the bottom of the orange line is where I should place the ball in the next frame. This worked fine and I was satisfied with it, until I started nailing the edge case of the ball hitting the T intersection, where it all goes bananas. What should happen here is that the ball bounces to the left and destroys either of the bricks. But what can happen is that my algorithms decides to choose the middle vertical segment (connecting boxes 1 and 2) as the collision point, either belonging to the 1st or 2nd box. I thought of ignoring the edges of the segments, but then the ball would pass right through the T intersection in this scenario, because it would also ignore what it's supposed to hit. You can see it in action here (around after 00 07 mark) https www.mp4upload.com p6966u6kuzad What are common techniques for handling this case? Even if I introduce the width to the ball, it could still hit the exact T intersection at the tangent, so the problem would remain. Requested to post code. Here's the main bit. Please note that I'm not expecting you to (or looking for) debugging the application. I'm more asking about how are these things even handled in general. export function bounceBall( ball Point, vx number, vy number, obstacles Obstacle , ) const projectedNextPoint ball.clone().translate(vx, vy) const movement new Segment(ball, projectedNextPoint) const touchedObstacles Obstacle let loop 10 let hasCollision false do hasCollision false if (loop lt 0) throw new Error('oops') If in the previous loop the ball just grazed the surface if (movement.isZeroLength()) break const collisions Collision for (const obstacle of obstacles) const collision getIntersectionOfSegmentAndObstacle ClosestToStartExcludingStart(movement, obstacle) if (collision ! null) collisions.push(collision) const collision getClosestCollisionExcludingSelf(movement.start, collisions) We don't count a collision if it's the starting point. If we did, grazing a surface would turn into an infinite loop. if (collision null Point.AreEqual(collision.point, movement.start)) hasCollision false else hasCollision true touchedObstacles.push(collision.obstacle) if (hasCollision) movement.setStart(collision!.point) if (collision!.segment.isVertical()) movement.mirrorVerticallyWrtStart() vx vx if (collision!.segment.isHorizontal()) movement.mirrorHorizontallyWrtStart() vy vy while (hasCollision) return touchedObstacles, vx, vy, newBall movement.end,


Tiled height level collision I have created the below tilemap in tiled and I am wondering about a good approach to "separate" these two different heights in the map. I would like to keep it tile based, so adding a object layer for collision detection is a no for me. I would like the player to move from the low ground to high ground using the ladder. But as you can see, two walkable tiled adjacent to each other should not be "connected" since they are on different heights. Since I can only add properties to the tile in the sheet and not on the map itself afaik, I cannot mark the heights on my map. So I guess I have to work with different layers for each height. Check if the layer the player currently on has a tile or something, if that is even possible. The reason I do not want to use a object layer is simple. My creatures move from tile to tile and I just want to check if that tile is walkable and on the same height level. No need to test vs a rectangle or polygonal object. What I am actually looking for is having properties per coordinate. This would make it a lot easier (pseudo code) tileMap x y .floorCount tileMap x y .walkable instead of map.getLayer(player.currentLayer).layerMap x y .tileExists map.getLayer(player.currentLayer).layerMap x y .walkable I simply cannot add properties to a "global" tile (tiled seems to only allow me to add properties to the tile on the sheet which is carried over to every usage of it. This image uses that same corner tile as in the above image, only this time the player is allowed to cross it, or perhaps hop over it.


Handling strange physics behaviour while sliding between coplanar surfaces We've got a character setup based around manually resolving collisions, and we're using bullet to do so. Our characters have a kinematic rigidbody to push things around, but their movement and positioning is done using a separate (pair caching) ghost object. Every physics tick we iterate over all contacts for that ghost and resolve collision either by depenetrating 100 when it's ground, or by depenetrating gradually not at all with walls or other characters. We then apply our ghost's new position to the kinematic rigidbody so that can interact with other physics objects. Unfortunately, when moving around a flat world made up of a bunch of coplanar blocks, when the characters moves from one block to another it will often do one of two things Fall through the cracks Get bumped upward a significant distance (we're talking up to half a unit meter with a character that is 2 units meters tall) Debugging this tells me sometimes these contact points are unexpected, and not something I want to resolve by depenetrating 100 . Gravity moving the character downward can result in a contact point that is closer to the side of the terrain block than the top, and it will give you a normal distance accordingly (blue arrow). Resolving that with 100 depenetration will just push you in between the blocks, while not counteracting the gravity forces. This would explain the falling through the cracks. But I don't know why I sometimes get contact points with normals pointing straight up, but with a distance that would place the collider far above the ground (purple arrow). I've come to the point where I feel like my only option to handle character movement like this is by not colliding with the ground at all, and just spherecast downwards at the character's position on the horizontal plane just to place it down on the ground properly. Now obviously I want to get rid of this behaviour. And seeing how you don't see this happen in many games, I'm lead to believe others have solved this issue somehow. Has anyone here encountered similar issues, and how did you go about fixing them?


Weird issue in collision resolution of non static bodies I'm a bit of a beginner in engine development, so I decided to write my own engine from scratch so I could learn more about what happens under everything. I've been progressing fairly well, except the physics engine side of things have been giving me a bit of a headache. Here's a gif of what I mean Essentially, the engine works just fine as long as the player is not colliding with another non static body from either above, or from right to left. Here's my collision resolution code written in go package resources import ( "game pidgeot socket ecs" "github.com bxcodec saint" ) type PhysicsSystem struct Hub Hub func (system PhysicsSystem) Loop() entities, err system.Hub.World.AllEntitiesWithComponent(ecs.CollisionComponent) if err ! nil return for e, range entities apply impulse c p, system.Hub.World.GetComponent(e, ecs.CollisionComponent) c ( c p).( ecs.Collision) p p, system.Hub.World.GetComponent(e, ecs.PositionComponent) p ( p p).( ecs.Position) if c.WithGravity Add gravity c.ImpulseY saint.Min(c.ImpulseY 1, c.MaxSpeedY) apply impulse p.NextY p.Y c.ImpulseY p.NextX p.X c.ImpulseX resolving collisions for e1, range entities c1 p, system.Hub.World.GetComponent(e1, ecs.CollisionComponent) c1 ( c1 p).( ecs.Collision) if c1.IsStatic continue for e2, range entities if e1 e2 continue system.ResolveCollision(entities, e1, e2) moving entities for e, range entities p p, system.Hub.World.GetComponent(e, ecs.PositionComponent) p ( p p).( ecs.Position) if (p.X ! p.NextX p.Y ! p.NextY) p.X p.NextX p.Y p.NextY system.Hub.broadcast lt system.Hub.World.GetComponentMessage(e, p p) func (system PhysicsSystem) ResolveCollision(entities map ecs.EID ecs.Component, e1 ecs.EID, e2 ecs.EID) c1 p, system.Hub.World.GetComponent(e1, ecs.CollisionComponent) p1 p, system.Hub.World.GetComponent(e1, ecs.PositionComponent) c1 ( c1 p).( ecs.Collision) p1 ( p1 p).( ecs.Position) c2 p, system.Hub.World.GetComponent(e2, ecs.CollisionComponent) p2 p, system.Hub.World.GetComponent(e2, ecs.PositionComponent) c2 ( c2 p).( ecs.Collision) p2 ( p2 p).( ecs.Position) resolve y axis collidingX IsOverlapping(p1.X, p1.X c1.W, p2.X, p2.X c2.W) collidingY IsOverlapping(p1.NextY, p1.NextY c1.H, p2.NextY, p2.NextY c2.H) colliding collidingX amp amp collidingY if colliding direction func (impulse int) int if impulse lt 0 return 1 else return 1 (c1.ImpulseY) overlap CalculateOverlap(p1.NextY, p1.NextY c1.H, p2.NextY, p2.NextY c2.H) p1.NextY (direction overlap) c1.ImpulseY 0 c1.IsJumping false resolve x axis collidingX IsOverlapping(p1.NextX, p1.NextX c1.W, p2.NextX, p2.NextX c2.W) collidingY IsOverlapping(p1.Y, p1.Y c1.H, p2.Y, p2.Y c2.H) colliding collidingX amp amp collidingY if colliding direction func (impulse int) int if impulse lt 0 return 1 else return 1 (c1.ImpulseX) overlap CalculateOverlap(p1.NextX, p1.NextX c1.W, p2.NextX, p2.NextX c2.W) p1.NextX (direction overlap) for e3, range entities if e1 e3 continue c3 p, system.Hub.World.GetComponent(e3, ecs.CollisionComponent) p3 p, system.Hub.World.GetComponent(e3, ecs.PositionComponent) c3 ( c3 p).( ecs.Collision) p3 ( p3 p).( ecs.Position) collidingX IsOverlapping(p1.NextX, p1.NextX c1.W, p3.NextX, p3.NextX c3.W) collidingY IsOverlapping(p1.NextY, p1.NextY c1.H, p3.NextY, p3.NextY c3.H) colliding collidingX amp amp collidingY if colliding system.ResolveCollision(entities, e1, e3) Anything I could do to solve that issue?


How to simulate cylinder shape in collision detection? AFAIK, many physics engines like Physx and Havok don't incorporate cylinder as basic shape because it is expensive than sphere, box and capsule. But bullet engine does incorporate cylinder as a basic shape. Do they found any fast algorithm to simulate the cylinder and what is that?


Ellipsoid v. Box collision detection I'm trying to write some collision detection code. ATM i have the code properly resolving Ellipsoid v. Ellipsoid collisions, and Box v. Box collisions, but Ellipsoid v. Box collisions doesnt work. In general how do you test for interesection between these two. What i've been doing is Finding the closest point on the ellipsoid to the box, and vice versa. vector3 closestVertexOnBox Closest vertex on the box to the ellipsoid vector3 closestPointOnEllipsoid Closest vertex on the ellipsoid to the box In this case ( ellipsoid v. box ) you have 4 axes. The axis from the center of the circle to the nearest point on the box. The X,Y,Z standard axes ( assuming its an AABB ) Put them all in an array vector3 axes normalize( closestVertexOnBox ellipsoid.origin ), unitX, unitY, unitZ Then for each axis in that array, Project the vector from the center of each shape, to its vertex closest to the other shape onto each axis to find the projected half widths. float minOverlap infinity vector3 overlapAxis for each axis in axes float prjBoxHalfWidth Dot ( axis , closestVertexOnBox box.origin ) float prjEllipsoidHalfWidth Dot ( axis , closestPointOnEllipsoid ellipsoid.origin ) If the sum of any of the projected half widths are smaller than the projected distance between the two, then their is no collision float prjDistance Dot( axis , box.origin ellipsoid.origin ) if(prjBoxHalfWidth prjEllipsoidHalfWidth lt prjDistance) return no collision Now get the axis with the least overlap out of all of them float overlap prjBoxHalfWidth prjEllipsoidHalfWidth prjDistance if(overlap lt minOverlap) minOverlap overlap overlapAxis axis Then resolve the overlap ellipsoid.origin overlapAxis minOverlap 2 box.origin overlapAxis minOverlap 2 Thats pretty much my ( pseduofied ) code. If thats good, then i might have an error, but thats wrong, then what am i not taking into consideration or forgetting.


relationship between eye height and collision body in UDK We are using the UDK in a research lab setting so we must understand exactly how tall users feel in the virtual world (camera position). By Googling and digging through code, we have discovered the BaseEyeHeight parameter and also the dimensions of the collision cylinder (CollisionHeight). We attempted to set these using Remote Control and could not deduce the relationship between the variables. For one thing, it seems that BaseEyeHeight has a ceiling. We cannot set it arbitrarily high but the height that is allowable seems to be dependent on the height of the collision cylinder, though it can be higher than the cylinder. Is there a ceiling for the eye height? Secondly, the height we set for the collision cylinder does not seem to match the height of an object in the world that should be the same height. Is the collision cylinder in the same units as the rest of the world? Is there some padding that I am not accounting for? Finally, BaseEyeHeight does not seem to be the height from the ground. I read somewhere that it should be the height from the center of the cylinder. Is this true? I would expect the eye height to be a bit lower than the actual collision height (as in the real world). Is this the case? The big picture problem is that we cannot find a diagram or detailed description of how these numbers relate to one another. Is there a comprehensive source we've missed?


GJK point in tetrahedron capping the number of searches? The very informative mollyrocket video has given me quite a lot to work with, but one thing that the video seems to suggest is that the algorithm should ideally run until it definitely determines whether or not there's a hit. I was of the idea that if there's no collision, it would be obvious by testing the dot product of the latest point against the search direction if it is not positive, then we did not pass the origin, so a tetrahedron which encloses the origin simply cannot be built. In cases where there is a hit OR a clear miss, the routine typically picks up less than 11 loops through. However, as I tend towards 'questionable territory' and the definitive hit miss is visually less distinct, there are times when the method apparently continues to pass the origin yet construct unsuccessful simplexes. Is it common to cap this kind of function at a max number of tries? Right now I am somewhat arbitrarily using the number of points in one shape times the number of points in the other shape in other words max tries len(shape1.pts) len(shape2.pts) It feels a bit hacky and I have to assume that the routine is geared towards simply running ad nauseum until it smacks into a clear hit miss situation. Has anyone experienced this before? Is this a problem or an anticipated safety measure in such an algorithm? If it needs to be done I'll gladly share some code, but I think it stands as self evident that it is kind of a longer read than most code snippets so I've abstained for now.


OBB vs rectangle quad plane with bounds collision detection response I am able to resolve collision between an OBB and a plane but can't get it to work when I introduce some bounds on the plane size. I want to have the plane of width and height dimensions defined by a normal and a position. The code for detecting resolving is fairly simple if the plane doesn't have any bounds function obbIntersectsPlane( obb, plane ) let r obb.size.x 2 Math.abs( dot( obb.right, plane.normal ) ) obb.size.y 2 Math.abs( dot( obb.up, plane.normal ) ) obb.size.z 2 Math.abs( dot( obb.forward, plane.normal ) ) let s dot( plane.normal, obb.position ) dot( plane.normal, plane.position ) if ( Math.abs( s ) lt r ) return overlap r s, vector plane.normal return false


Collision intepenetration and objects getting stuck (Unity) I am having what is probably a newbie problem with Unity, but for the life of me, I can't find a decent solution to it. In short my rigid bodies collide, but sometimes, they interpenetrate and stay stuck. I am looking for a solution that would either 1 stop the interpenetration from even happening 2 or at least eject the bodies to 'unstuck' the collision. By making the physics fixed step 0.01 instead of the default 0.02, I can avoid some of the interpenetration. However, that hardly sound like the proper way to fix this problem. Here is a screen shot of the bodies colliding. The car on the right is shown completely and you can notice that the ones behind have penetrated the others to some extent. To give more information that could be relevant There is no gravity All the objects have rigid bodies Their sizes are 3.5 x 6.8 and they are moving at 8 to 50 m s Each object has a conpounded collider made up of 3 box colliders If I change the fixed step to 0.01 there is a lot less more interpenetration (as I mentioned). Other physics settings do not seem to have any effect The object is moved by setting its velocity in the FixedUpdate function with rigidbody.velocity XYZ until there is a collision, then there is no more processing done in FixedUpdate at all. I detect the collision with OnCollisionEnter and set a flag. I haven't set any collision material, but I can't see that being a factor? Solved Thanks to everyone who helped me with the issue. There were a few factors in play. First, there was the scale. What I did to figure this one is create an empty scene and put 2 cubes in there. I varied the size and position of the cubes (from 68x35 to 0.65x0.35 for size and the position by factors or 10 as well) and attached a script to move them, with variation in speed by factors or 10 as well. So all else being equal (same size on the screen and time to cross it), the size of the objects elected a different response to collision big object got interpenetration, small ones none. I am not familiar enough with Unity to explain the cause of that, but it is reproductible. A possible second factor was the shape of my colliders and how it may be possible that they screwed up the ejecting part. The colliders I had were not overlapping, so I simplified them to 2 boxes in the shape of a cross. Finally I was setting the position of the objects manually in FixedUpdate and that caused some problems with interpenetration at lower scale (at higher scale, it didn't appear to matter). I changed that to work with the body velocity and it helped.


Collision causing First Person Controller to go haywire I have created a first person controller as an enemy in my game (Zombie). My character is an archer that uses arrows as projectiles that are shot with the following code if(Input.GetButton("Fire1")) shotForce 45f if (Input.GetMouseButtonUp(0)) Rigidbody shot Instantiate (projectile, shotPos.position, shotPos.rotation) as Rigidbody shot.mass shotMass shot.AddForce (Camera.main.transform.forward shotForce) shotForce 0f I have a script to parent the fired arrow to the collided object which works fine for most objects in the game, but my enemy object (Zombie) speeds up and moves all around the place on a collision, I'm new to unity, I've spent a few hours trying to resolve this with out success. I have a Rigidbody, Charcter controller and First person controller on the Zombie. I have a Rigidbody and Sphere Collider on the Arrow. The method I think is causing the problem void OnCollisionEnter(Collision collision) if (this.flying) this.flying false Destroy (this.GetComponent lt Rigidbody gt ()) this.transform.position collision.contacts 0 .point GameObject anchor new GameObject ("ARROW ANCHOR") anchor.transform.position this.transform.position anchor.transform.rotation this.transform.rotation anchor.transform.parent collision.transform this.anchor anchor.transform collision.gameObject.SendMessage ("arrowHit", SendMessageOptions.DontRequireReceiver) I think the issue is with the line anchor.transform.parent collision.transform Maybe there is a solution without parenting the arrow to the Zombie? I'm stumped at this stage any help appreciated.


Sprite Kit keeping character level with the terrain 2d endless runner I've been trying to figure this out exhaustively for the past few days and still haven't found an answer. I have an endless runner built using swift where the character is fixed and the terrain moves to the left. I have edge physics bodies on the terrain, and edge physics bodies that go up and down slopes. The problem is, if I want my character to collide with the ground without being pushed back by it, since the only thing that can make contact with an edge is a dynamic volume. My goal is to keep the character level with the terrain, (assuming they're not jumping). Even on slopes. I've tried ray casting using enumeratebodiesalongraystart, but can't seem to figure out how to get coordinates of where it intersects with the ground. I've tried having an edge body that is vertical, that intersects with the ground(two edge bodies cannot make contact in sprite kit). I've tried dynamic volumes. I've tried Static volumes. Nothing works. I'm not posting code here since I'm really just looking for a general answer to sort of point me in the right direction, but I'm coding in swift. Thanks in advance. Also I have the character in a different bitmaskcatagory than the terrain catagory and they are set up to recognize each other, and do if one of them is a dynamic volume physics body.


AABB Sweeping, algorithm to solve "stacking box" problem I'm currently working on a simple AABB collision system and after some fiddling the sweeping of a single box vs. another and the calculation of the response velocity needed to push them apart works flawlessly. Now on to the new problem, imagine I'm having a stack of boxes which are falling towards a ground box which isn't moving Each of these boxes has a vertical velocity for the "gravity" value, let's say this velocity is 5. Now, the result is that they all fall into each other The reason is obvious, since all the boxes have a downward velocity of 5, this results in no collisions when calculating the relative velocity between the boxes during sweeping. Note The red ground box here is static (always 0 velocity, can utilize spatial partitioning ), and all dynamic static collisions are resolved first, thus the fact that the boxes stop correctly at this ground box. So, this seems to be simply an issue with the order the boxes are sweept against each other. I imagine that sorting the boxes based on their x and y velocities and then sweeping these groups correctly against each other may resolve this issues. So, I'm looking for algorithms examples on how to implement such a system. The code can be found here https github.com BonsaiDen aabb The two files which are of interest are box Dynamic.lua and box Manager.lua. The project is using Love2D in case you want to run it.


Calculating radius during collision This picture is from one of Dirk Gregorius' presentations The original diagram has only one contact point (the red one). The r 1 and r 2 vectors are required to produce rotation while solving the contact constraints. I agree that the r 2 vector is correct, but I think that the r 1 vector should point towards the blue point (which I've added myself) It's not difficult to retrieve the blue point (just add the minimum translation vector to the red point), but I've seen contrasting depictions of what points the contact manifold consists of. Excluding the parallel edge edge case, should the contact manifold consist of two points (the deepest points of each shape) or just one?


Tiles and a walkable path My game a sidescrolling platformer. I've created my own Tile app which in the end export an xml file detailing what each 32x32 space (in the entire image) contains (environment, platform, etc.). I get how to use it for static things collision detection and quad trees and so forth but still have no clue how to use this map xml file for keeping my character on a path in my background image which in my case is a hill with lots of odd curves. Also, yes, there are tutorials on tile movement, but they are mostly movement from a top down view which is slightly more trivial to implement. 80 of the image in my game is just a pure background and the very bottom are bricks covered with grass with some weirder angles. The thing is, I can have mixed tiles of empty space and grass which contains a part of a curve so I don't know how I would want the player leg to interact with this. Can anyone give me an idea or an example?


Swift How do I detect the exact point at which two "SKPhysicsBody(edgeFromPoint " type physics bodies intersect in sprite kit I have two physics bodies attached to two separate sprite nodes using Sprit Kit. One is a vertical line and one is a horizontal line sprite with horizontal physics body spriteMatrix i j .physicsBody SKPhysicsBody(edgeFromPoint CGPointMake(0, tileSegmentHeight), toPoint CGPointMake(tileSegmentWidth, tileSegmentHeight)) spriteMatrix i j .physicsBody!.categoryBitMask self.surfaceCatagory spriteMatrix i j .physicsBody!.contactTestBitMask heroCatagory sprite with vertical physics body self.hero.physicsBody SKPhysicsBody(edgeFromPoint CGPointMake(self.hero.frame.width 2, self.hero.frame.height 2), toPoint CGPointMake(self.hero.frame.width 2, 20)) self.hero.physicsBody!.categoryBitMask heroCatagory self.hero.physicsBody!.contactTestBitMask surfaceCatagory What I'm want to do is test if they are intersecting on every frame, and if they are, return the x and y position of where they are intersecting. Is this even possible?


Half top down view collision and mechanics I'd like to create a game with a half top down (2d RPG) view (I don't know the exact name of it). It would be 2d, but I'd like to add 3d like collisions. For example If the grenade lands on the roof, it would roll down and fall. Or if it hits a wall, it would bounce back. I've never worked with this view, that's why I'm asking for advices for how to do proper collisions and physics. I don't want to use any external libraries. Thanks in advance!


What are the advantages and disadvantages of overlap testing and intersection testing? I have been looking for the advantages and disadvantages of both overlap testing and intersection testing, but I was only able to find a few disadvantages overlap testing may fail for objects moving very fast, and intersection testing makes assumptions that may lead to wrong predictions, such as a constant speed and zero accelerations. What are the advantages and disadvantages of overlap testing and intersection testing?


body entered signal won't emit when rigidbody collided to rigidbody I have multiple rigidbody object floating away in the space. When they hit each other, they push away each. I want to destroy object if they hit something, but connect body entered signal won't invoked when they impact each other func ready() connect("body entered", self, "destroy") func destroy(body) print("HIT!") queue free() How do I check Rigidbody hit something?


Simple Bounding Box Multiple Collision problem I'm making my first game, and in it I use a moving ball to hit static blocks (kinda like breakout). Basically, I loop through all of the static blocks on the screen each frame, update the position of the ball based on its velocity, and if it collides with a block, the ball will bounce back off of the block. If the ball hits one block exactly, then there is no problem whatsoever. But if the ball happens to hit two blocks at the same time (that is, it hits in between both blocks), it passes right through both of them no deflection whatsoever. (I know the looping is inefficient and I'm looking to correct that later, but if it has to do with the problem, I just hope someone can point to me why it is that the collision resolution fails when two similar objects are hit at once.)


Javascript canvas check if all recs on the screen overlap a new one So I know the AABB collision detection formula, however, this code does not work. Whenever I press space, a new square pops up. But this new square can spawn inside another, something that I do not want to happen. Here is a snippet of the code I think is going wrong var xTopsBotsYTopsBotsSquares Makes a randint() function. function randint(min, max) return Math.floor(Math.random() (max min 1)) min function checkForOccupiedAlready(left, top, right, bottom) if (xTopsBotsYTopsBotsSquares.length 0) return true for (var i 0 i lt xTopsBotsYTopsBotsSquares.length i ) var data xTopsBotsYTopsBotsSquares i if (data 0 lt right data 1 lt bottom data 2 gt left data 3 gt top) Do nothing else return false return true Makes a new square function makeNewsquare() var checkingIfRepeatCords true DO loop that checks if there is a repeat. do Makes the square x y positions var squareRandomXPos randint(50, canvas.width 50) var squareRandomYPos randint(50, canvas.height 50) Tests if that area is already occupied if (checkForOccupiedAlready(squareRandomXPos, squareRandomYPos, squareRandomXPos 50, squareRandomYPos 50) true) xTopsBotsYTopsBotsSquares.push( squareRandomXPos, squareRandomYPos, squareRandomXPos 50, squareRandomYPos 50 ) console.log(squareRandomXPos, squareRandomYPos, squareRandomXPos 50, squareRandomYPos 50) checkingIfRepeatCords false while (checkingIfRepeatCords true)


Efficient Collisions Iteration? My project has upwards of 3000 2D objects but not all of them collide with each other. Between each object that can collide, a CollisionPair is created and stored inside a flattened array. Currently, a MaxObjects is defined for accessing the flattened array. Unfortunately, when iterating over this array for collision checks, I get a lot of overhead from the for loop and null checks. Is there a more efficient way, both in memory and performance, to store and access CollisionPairs? Note Many of these objects are axis aligned boxes how does Minecraft handle these collisions?


How to create walls and rooms with Pixi I'm a JS dev but pretty new to Pixi and 2D developemnt so please bear with me as I explain this. I want to write a simulator for short path finding (for evacuation purposes). I decided to use Pixi.js for this since it seems capable of doing everything I need to do. I followed this tutorial to try to learn how Pixi works and if its right for this. The tutorial didn't seem to answer many questions I have and I still have some confusion. Before I dive into writing the code, I want to know how wall detection in Pixi acheived. Take the below map for example It is a 800 x 800 png file (where everything but the blue is transparent no grid lines ) that i can load into Pixi as a Sprite. I created it in Tiled editor. So it can be exported as a tilemap, JSON, CSV etc. When I export it as JSON, here is the file contents https pastebin.com zGh1XmR7 The blue boxes represent walls. I want to load in other various sprite objects so that it will look like this The people in the simulations cannot cross the blue walls and they cannot cross the pink circles (they represent danger zones). I intend to use easystar.js to find the shortest path to exits for the people sprites in the map. So my question is this, how does Pixi recognise the blue walls? Is it something I have to do when creating the tileset png? Like something defined in the JSON file for the tileset atlas? Maybe SVG? Or is there a pixi function to do this? Is this the best approach to doing this and is Pixi even the best way to do this? I'm looking for a tried and tested solution or a pointer in the right direction.


How can I run a Phaser engine game without a window? I'm currently creating a multiplayer game using the HTML5 framework Phaser. It's a game where zombies spawn on the map and players have to shoot them to kill them. The zombies target players that are closest to them. Currently, I'm having my an issue with my design strategy. I'm not sure if this type of game is possible with Phaser due to the movement tracking. At present, the client is handling all of the player movement, so whenever a player moves, it broadcasts it to the server which sends it to all of the other clients. However, I would like for the zombies and the bullets to be controlled by the server exclusively. The server then updates each client with the velocity of each zombie and their current position. My reasoning is that anything that isn't player input should be calculated by the server. This will prevent issues such as two clients saying that a zombie died at different times and then trying to communicate with one another, having bullets at different locations at the same time, or zombies spawning at separate times between clients. Here's an example of a zombie class function Zombie(game, data) this.game game this.id data.id Phaser.Sprite.call(this, this.game, data.x, data.y, 'zombie') this.anchor.setTo(0.5,0.5) this.animations.add('right', 0,1,2,3 , 7, true) this.animations.add('left', 4,5,6,7 , 7, true) this.game.physics.arcade.enable(this) this.body.collideWorldBounds true this.health data.health this.maxHealth data.maxHealth this.speed data.speed this.target this.game.player this.waiting 100 this.name "zombie" this.healthBary 20 this.healthBar this.game.add.sprite(this.x, this.y this.healthBary, 'player health') this.healthBar.anchor.setTo(0.5, 0.5) CollisionManager.addObjectToGroup(this, 'baddies') this.game.add.existing(this) Zombie.prototype Object.create( Phaser.Sprite.prototype ) Zombie.prototype.constructor Zombie Zombie.prototype.update function() this.updateHealthBar() this.moveTowards(this.target) Zombie.prototype.uTarget function(target) this.target target Zombie.prototype.moveTowards function(target) var x target.x this.x var y target.y this.y var mag Math.sqrt((x x) (y y)) var nx x mag var ny y mag this.body.velocity.x nx this.speed this.body.velocity.y ny this.speed if(this.body.velocity.x gt 0) this.animations.play('right') else if(this.body.velocity.x lt 0) this.animations.play('left') Zombie.prototype.updateHealthBar function() this.healthBar.x this.x this.healthBar.y this.y this.healthBary var p (this.health this.maxHealth) p parseFloat(p.toFixed(1)) this.healthBar.frame 10 (p 10) Zombie.prototype. damage function(amount) this.health amount if(this.health lt 0) this.kill this.die(true) Zombie.prototype.die function(points) if(this.game) this.game.baddie die sfx.play() WaveManager.onMap CollisionManager.removeObjectFromGroup(this, "baddies") if(this.healthBar) this.healthBar.destroy() socket.emit("kill zombie", id this.id ) this.kill() this.destroy() The problem is that I can't create a Phaser game object on the server (as it's running on a Linux server) because there's no window that can be used. The bullets and zombies need to be Phaser objects for the sake of collision detection, but I can't do that on the server. I know that I could create a vector of zombies and bullets server side that would have the information for each bullet zombie's position at any given time and then update the client, but then I wouldn't be able to use the CollisionManager in Phaser. Right now, it seems like my only solution is to create my own collision detection system. Are there any alternative ideas?


Collision 100 avoidance implementation I'm an absolute beginner with game development and all I know about collision avoidance resolution, I learnt it on or through this site in the past week... so don't hesitate to correct me if what I'm asking here is based on wrong assumptions misunderstanding. I tried of my best to be clear, but that said, the subject is still novel to me. Vehicles In my game, I have vehicles that move autonomously. They are placed in a 3D space, and their motion is governed by a number of variables which are different for each vehicles. The one of interest here are primarily Only forward motion. A speed that can vary between min amp max, but whose min is not (even close to) zero. A steering radius that is dependent from the speed (the higher speed, the larger radius) Two maximum accelerations (for decreasing and increasing speed) Goal My goal is to implement some sort of AI that will a 100 accurate collision avoidance (i.e. I will be sure that the vehicles will never ever collide). Design Although I would prefer more the idea of having the AI "onboard" (i.e. each vehicle having it's own "collision avoidance AI", eventually querying and or sending messages to other vehicles) it is also possible for me to implement the CA AI at a central level (dispatching commands to the vehicles). In most of the cases, the vehicle will simply have to steer clear of each other in any direction, but under certain circumstances, they will have to avoid collision and going towards the same target What I found so far and where I got stuck Within the many many links I found in other questions on this very site, I found of particular use these ones Collision between pool balls Unalligned collision avoidance Queuing While these three links "opened my eyes" in many ways, it is not immediately clear to me how to use that information in my case. In particular article 2 only "tries" to prevent collision (but collisions do happens time to time). While article 3 needs to stop vehicles sometimes to prevent collisions. What I also noticed, is that the collision avoidance algorithms linked above use a "instant projection" of linear speed to check if something is on the way of the vehicle. I was wondering if this is enough in my case or if I had to project my position in a more realistic way (e.g. If I am 60 into a steering 90 to the right, I should calculate my position for the rest of the 30 of the curve, and then assuming linear motion). Finally, I am particularly afraid of deadlocks. In other words although the density of vehicles in the world will be fairly low, I am worried that given a certain numbers of vehicles converging towards the same point, once they will realise they are on a collision course, any evasive manoeuvres will be impossible as it would bring the vehicle on a collision path with some other ones. Question How can I reach my "goal"? An in depth explanation is of course very much appreciated, but links to external resources would also be of great help (I'm sure I'm not the first with this problem, but probably I used the wrong keywords to search the web?) Thank you in advance for your help!


Collision with walls in a completely tile based game I am making a tile based game, in which also the player movement is completely snapped to the grid. Imagine sokoban. I basically have a 2d array for the layout of the level (walls not walls), and the player can check is there's a wall where he is going. My question is, when the player is trying to move into a wall, should I Let it move into the wall, then later check if it's in a wall and if needed revert it's movement? Check whether it is going to move into a wall and prevent it beforehand? I understand the answer may heavily depend on the structure of my code, but I'd still like to hear some opinions about how it was done in the past. What do you think? which of the two is better? (or is there a third option)


Area attack collision resolving I'm planning to write little 2D go right and swing your sword game. When i started to write my ideas on paper i've come across a little problem. Let's say i'm using magic spell, ex. fireball which technically is a signle projectile flying slowly in a specified direction. As it's defined to be a piercing projectile, I want it to hit every enemy only once, no matter how big their sprites are. And how I do it? I know i can use the array of already hit enemies and check every frame if projectile collides something new, but is it a correct way? Are there any tried and true ways of resolving problems like this?


Multiple collisions within a single frame cycle? So say you want to simulate several objects in two dimensions, just bouncing around in a finite space. Using AABB and sweep tests, it shouldn't be that complicated to calculate single collisions between objects. But if you want to have an object bounce off another surface in the same frame (one collision), how do you account for any additional collisions after that first one? This might not make much sense, so I put a little graphic together to explain what I mean. So say all this is happening in one frame cycle. The gray box moves up and bounces off the wall on the top that's easy enough. That orange box is the problem, though. How do I calculate that collision as well (where the two translucent boxes are)? OR, if the frame rate is high enough, does it even matter? Thanks!


Spatial Hashing is set up.. now how should I go about actual collision logic? So I have a spatial hashing system set up and it works. It puts players in buckets based on their x y width height So I was going to check collisions on each frame when I loop through the entity for updating their physics. But how would I go about duplicate collisions? Say I'm checking for player a, which is in the same bucket as bullet a.. I check if there's a collision and there is, should I do the collision logic right there? Or should I add the collision to a list and iterate through that list at the end of the frame to handle the logic for each collision? This way I can also apply logic to prevent duplicate collisions. Or should I just do all the logic right there and then when the initial collision is made?


Collision detection in multiplayer games This a followup to my previous question How to implement physics and AoE spells in an MMO game?. There, we concluded that all physics have to be done on the server, and that I should use cylinders for calculations. Now, how can I check for collision detection on a ground to player basis on the server? It's fairly easy if the ground is a flat space, I just check if the player's z coordinate is lower than some value and voila, but, what if the map ground itself is a model? How do I know where hills are on the server side? How do I know when object collisions happen? I'm using node.js and socket.io.


Allowing one sprite to move through another in Quintus I have a Bumper class extended from Sprite Q.Sprite.extend("Bumper", init function(p) this. super(p, gravity 0 ) this.add("2d, ... etc. I have an Enemy class that should trigger a function when the center of the Bumper and of the Enemy collide. I was thinking about doing something like this in my Enemy class this.on("bump.top, bump.bottom, bump.left, bump.right", function(collision) if(collision.obj.isA("Bumper")) if (this.p.x collision.obj.p.x amp amp this.p.y collision.obj.p.y) Do something ) But for that I need the two sprites to move through one another. Is there a way to do that while still checking for collision ?


What is the correct formula for penalty forces? I am trying to add penalty forces between two hard body objects, so when they collide they move in a realistic way. What I have so far is this var totalMass aMass bMass var temp (aMass totalMass aVelocity) (bMass totalMass bVelocity) newVelocityB (bMass totalMass bVelocity) (aMass totalMass aVelocity) newVelocityA temp Originally I thought this was correct and it seems to work for the most part. However, this doesn't seem to be flawless. For example, if the collided object is a vertical wall (represented with a mass of infinity), the wall's velocity of (0,0) will be the final result. So, for an object moving diagonally with a velocity of (10,10) and hitting the wall, will result in a velocity of (0,0). In my case I would expect that the y component of the velocity remains 10, and it keeps sliding up the wall. Can anyone tell me if I'm on the right path, and how I can modify my formula to make sure that the y velocity does not become 0? I have considered that the collision normal of the wall could be important (in this example 1, 0 ), or the perpendicular of the normal, however I still have not figured out how to apply it in this formula. Multiplying by the perpendicular of the normal was my first idea, but this isn't the correct answer.


How can I reproduce the physics that we can see in Dawn of Titans? I'm working on a hobby RTS project and I want to implement collision physics between soldiers like in the mobile game Dawn of Titans. Here is a video reference https youtu.be Fnpot2NeJl8?t 341 How can I achieve this?


2D Rope Collision Detection I'm wanting to create a rope that can collide with objects like in the following youtube video 2D Game Physics Rope I'm thinking that you implement the verlet integration which uses points and connects these points with lines. I'm trying to figure out what type of collision detection you would apply to the rope to get the effect in the video. I'm thinking you would have to do some cd to each point. I would like to use box2D, so I'm wondering would making each point a rigid body work? Any advice would be appreciated.


Are there well known algorithms for fitting a polygon to an arbitrary shape? I'm using the Chipmunk physics engine to make the levels for a 2D C game. I'd like to be able to fit a polygon to an arbitrary shape to serve as the collision mask. Given a black and white collision mask for an arbitrary level object like this Are there any well known algorithms for getting this I could then use the red polygon to create a physics object to go with the image.


Pixel perfect collisions for platforms I'm trying to create pixel perfect collision detection but I don't know how to handle collisions when there is a jump. Here I have one image of a sample map But maybe I had a bad supposition assuming that all the pixels are little collision points. I mean , there is no differences between y axis collision and x axis collision in my collision map. I have been treating each axis collision split, but that is bad done when diagonal jump have been made, cause you'll get an error in x or in y while correcting the position. Then I thought that maybe I was wrong in my supposition that I didn't need to split for pixel collision type. I will resume it in 2 questions how can I handle pixel perfect collisions for a platformer? if I'm doing it well, How to manage the x axis, y axis problem? P.S My 'player' uses a box collider.


Delaying certain actions functions in libgdx using Timer? Hello I am trying to delay a part of the processes in my game, but it happend that I use one of my variables in an inner class so I have to make it final, but by making it final I can't assign new value when I find it. All I am asking for is to explain me how to do the delay without making my variable final. Here is my code public class TomatoScript implements IActorScript private CompositeActor tomato private static final int speed 100 private BitmapFont bFont private Batch bch ArrayList lt FruitScript gt fruits private final int dmg 10 private int hp 50 private Rectangle bounds private int state 0 private FruitScript collidetFruit private boolean dead() return hp lt 0 private void setHp(int dmg) hp hp dmg public TomatoScript(Batch b, BitmapFont bf, ArrayList lt FruitScript gt fruits) this.bch b this.bFont bf this.fruits fruits Override public void init(CompositeActor entity) this.tomato entity tomato.setPosition(200, 129) bounds new Rectangle(tomato.getX(), tomato.getY(), tomato.getWidth(), tomato.getHeight()) bch.begin() bFont.draw(bch, Integer.toString(hp), tomato.getX() 20, tomato.getY() 95) bch.end() Override public void act(float delta) switch (state) case 0 tomato.setX(tomato.getX() speed delta) bounds.setX(tomato.getX()) bch.begin() bFont.draw(bch, Integer.toString(hp), tomato.getX() 20, tomato.getY() 95) bch.end() if (tomato.getX() gt 1090) tomato.remove() if (collisionFound()) state break case 1 if (collisionAct(collidetFruit)) state 0 break private boolean collisionFound() for (FruitScript f fruits) if (f.getBounds().overlaps(bounds)) collidetFruit f return true return false private boolean collisionAct(FruitScript f) com.badlogic.gdx.utils.Timer.schedule(new com.badlogic.gdx.utils.Timer.Task() Override public void run() f.setCol(true) here it says I should make the "f" final. f.setHp(dmg) here also. setHp(f.getDmg()) ,2) if (f.dead()) fruits.remove(f) return true if (dead()) if (!f.dead()) f.setCol(false) tomato.getScripts().remove(this) tomato.remove() return false return false Override public void dispose() I've tried to make it final, but it ruins everything it's supposed to stop the actors do the damage taking and then the one alive to continue, but it was doing it too fast in a blink of an eye. When you make the f final, it can't get the new item it should collide with. I hope someone can help )


What data should a generic collision detection system gather? I'm working on a relatively generic 2D AABB collision detection system for a game engine, and I've re written it more times than I'd like to admit, due to not calculating or recording specific details of each collision. Right now, this is what I'm collecting Collision time as a fraction of an update cycle in the game loop. Location of the collision. ID of the colliding object. Each object has a Set that holds this data for each collision (I'm working with a component entity system) so other systems can use the recorded data. The problem I just ran into was that I needed to know which side of the object the collision takes place on. What other values or points of interest should I calculate or record, per collision? What do you look for in a standard collision detection system?


Voxel traversal for parabolic projectile arc under constant gravity For linear polynomials, there's a bunch of algorithms for efficiently determining which voxels to test for collision (eg. A Fast Voxel Traversal Algorithm for Ray Tracing ). I'm having troubles though, searching for algorithms that work for any other case, such as a parabolic projectile arc under constant gravity. Are there any algorithms for that case, or am I stuck just trying to sample at a high enough frequency that only rarely will a projectile travel though a wall without getting detected.


Should I do intersection testing in world or object space? I'm adding basic ray casting and collision detection for my game, and also adding bounding volumes and collision meshes. The ray is cast in world space and each mesh's node can track its world transformation. Considering I want to test for intersection between a ray and bounding volume and also bounding volume with other bounding volume, in what space should I perform the intersection test? Scenarios that I have in mind Transform ray into object's local space, perform test, then inverse transform the resulted point. Transform bounding volume into world space and perform it there, or should I always keep bounding volumes in world space? Perform bounding bounding test in world space or one of the objects? Do things change much between static and dynamic collision regarding used spaces?


What algorithms exist for generating collision geometry from an image? I am currently working on a game using SFML and Box2D. I am interested in generating collision geometry from the sprite data that I load into SFML. So, for example, an algorithm that would do this would take an image and find the edges (for example where the alpha area starts) and then generating a polygon that fits to those edges. Can I be pointed to any resources that describe an algorithm to do this?


Rotated Sprites collision detection I am trying to implement checkCollision function in my game, I used AABB method but the problem is that my sprites are rotated so it's not really precise. I could finely describe my Sprites with rotated ellipses. Is there any more precise way of detecting the collision if I have the following attributes of entities entity.x entity.y entity.width entity.height entity.angle Here is what I have coded so far (x and y are in the middle of my sprite) this.checkCollision function(entity1, entity2) return (entity1.x (entity1.width this.COLLISION EPSILON WIDTH) 2 lt entity2.x (entity2.width this.COLLISION EPSILON WIDTH) 2 amp amp entity1.x (entity1.width this.COLLISION EPSILON WIDTH) 2 gt entity2.x (entity2.width this.COLLISION EPSILON WIDTH) 2 amp amp entity1.y (entity1.height this.COLLISION EPSILON HEIGHT) 2 lt entity2.y (entity2.height this.COLLISION EPSILON HEIGHT) 2 amp amp (entity1.height this.COLLISION EPSILON HEIGHT) 2 entity1.y gt entity2.y (entity2.height this.COLLISION EPSILON HEIGHT) 2) PS my cousin told me to do it with three circles (which creates a shape very similar to the ellipse) but I do not really know how to do it.


Have the character automatically slide around obstacle corners Like this The player is only holding right, however the character still moves up a bit to go around an obstacle. My current collision system has access to The entity's previous position The entity's current position The entity's (axis aligned) bounding box All the obstacles and their (also axis aligned) bounding boxes Also it proccesses each axis separatelly. How can I implement this?


Problems about oriented bounding boxes collision detection I get a question for the following code which detects if two OOBs collide by SAT. The OBBs struct is also listed below. struct OBB Point c OBB center point Vector u 3 Local x , y , and z axes Vector e Positive halfwidth extents of OBB along each axis int TestOBBOBB(OBB amp a, OBB amp b) float ra, rb Matrix33 R, AbsR Compute rotation matrix expressing b in a s coordinate frame for(inti 0 i lt 3 i ) for(intj 0 j lt 3 j ) R i j Dot(a.u i , b.u j ) Compute translation vector t Vector t b.c a.c Bring translation into a s coordinate frame t Vector(Dot(t, a.u 0 ), Dot(t, a.u 2 ), Dot(t, a.u 2 )) Compute common subexpressions. Add in an epsilon term to counteract arithmetic errors when two edges are parallel and their cross product is (near) null (see text for details) for(inti 0 i lt 3 i ) for(intj 0 j lt 3 j ) AbsR i j Abs(R i j ) EPSILON Test axes L A0,L A1,L A2 for(inti 0 i lt 3 i ) ra a.e i rb b.e 0 AbsR i 0 b.e 1 AbsR i 1 b.e 2 AbsR i 2 if (Abs(t i ) gt ra rb) return 0 Test axes L B0,L B1,L B2 for(inti 0 i lt 3 i ) ra a.e 0 AbsR 0 i a.e 1 AbsR 1 i a.e 2 AbsR 2 i rb b.e i if (Abs(t 0 R 0 i t 1 R 1 i t 2 R 2 i ) gt ra rb) return 0 Test axis L A0xB0 ra a.e 1 AbsR 2 0 a.e 2 AbsR 1 0 rb b.e 1 AbsR 0 2 b.e 2 AbsR 0 1 if (Abs(t 2 R 1 0 t 1 R 2 0 ) gt ra rb) return 0 reset code are omitted For the part "Test axes L A0,L A1,L A2", why do we multiply each b.e i by the component from each axis in a's coordinate frame then add the result together? I know this part want to project the half positive extents onto each axis in a's coordinate frame, but it should do the dot product with the b.e vector and the projected axis, am I wrong? (that is b.e 0 AbsR 0 i b.e 1 AbsR 1 i b.e 2 AbsR 2 i ) For the part "Test axes L B0,L B1,L B2", It seems a.e vector is multiplied by each axis in a's coordinate frame, why don't transform the a.e vector into the b's coordinate frame since they are not at the same coordinate frame? For the part "Test axis L A0xB0", Why can we get ra and rb values by that arithmetic operation? What does Abs(t 2 R 1 0 t 1 R 2 0 mean?


How to store 3D entity position, offset, and transformation data for parent and children? I am looking for a cleaner pattern to storing character position data, offsets, and transformations. I currently have a character with a vec3 for position. Entity position vec3 rotation vec4Quaternion velocity vec3 I use this position vector as the world coordinate. So that when Y 0 I imagine the characters feet are on the ground. This makes it easier to think about where the entity is in world space. The problem I am having is that mesh entities like colliders or the skin mesh will assume a position vector at the center of the mesh. This is causing me to have to do a bunch of transformation juggling. I can't 1 to 1 map these meshes to the entities world position. I will update my characters 'ground position' when they move. then have to calculate the new 'center position' which is calculated like centerPosition groundPosition.x groundPosition.y entityHeight 2, groundPosition.z I"m wondering if there is a better pattern for this. Maybe I assume the entities position vector is a 'center position' as well? but not clear to me how to handle the ground offset in that case.


How to handle objects at the edges of spatial partition cells? A lot of games store object positions as floats and have a closed ball for the game area (eg. a rectangle and objects are allowed to have position coordinates on all 4 edges). However, this becomes problematic when partitioning the game area (eg. gridding quadtrees). The edge cases would have to be added in so that 2 edges of the game area are included in rectangles that touch them or objects on 2 edges would have to be missed out in the partition. Is there another solution to this or do games (and other programs this applies to) usually go with one of the above 2? (One solution is to use integer coordinates, but what if using floats is unavoidable?)


Bringing islands close together programmatically I generate island continent maps and I want to make a grand archipelago of sorts where all these islands are located. The problem is that I don't know a smart way to place the islands programmatically so that the keep a minimum distance from each other. Sure, I can create a quadtree but then how do I place it? Placing it on top of another island and move it away in a random direction? I'm attaching a photo of what I want to do, easily done in Paint .NET from 6 individual maps. The scale I'm talking about would be placing about 3 10 continents, each with a resolution of 4Kx4K upwards. (I'll only allow reflections and translations in placement, to preserve some 4 8 connectivity pixel work that I've done for the maps) What I'm NOT looking for a global minimum solution ( all islands as close together as possible) using a heavyweight physics maths library or tons of code a super simplistic solution either (e.g. calculate OBBs and use those to resolve collisions)


Python Pygame Collision problems I'm currently developing a game in Python Pygame and i came up with a problem with the player and the platforms. The game is a 'runner' where the player it's fixed (The 'x' position isn't variable, only the jump). This is how i'm currently doing the collisions managment def collide(self, yvel, platforms) for p in platforms if pygame.sprite.collide rect(self, p) if yvel gt 0 self.rect.bottom p.rect.top self.onGround True self.yvel 0 if yvel lt 0 self.rect.top p.rect.bottom 'platforms' its a RenderUpdate group with the platforms (a simple sprite). When the player is falling from a platform and collides with the next platform, not exactly on top of it but a little below, that's when the character jumps to the position shown in the code above, rather than collide and fall. I don't know how to check the left bound without a 'xvel' parameter. (The screen shows an example, but the player only changes the y axis coordinates, the platforms are updating their position) I've tried supply a number to a 'xvel' parameter, and check if the character wasn't on the ground (Jumping) and the 'xvel' was greater than 0, but it isn't working at all. Thanks in advance.


JavaScript 2D Top down Collision Detection issue I'm developing a 2D Top down Game using HTML5 Canvas and a custom Game Engine. I'm implementing the Quad intersection detection (Function below, if it helps) on different areas of the Sprites (As they're larger than Tiles in some cases), and have thought of an issue with this. I want to check these areas before moving, using the amount of pixels I will move if allowed to (Nothing blocking the character). Below if the code I use to move the Player move function(delta) var distance Math.floor(this.getSpeed() Math.floor(delta 10)) this.setMoving(false) if(Engine.input().isPressed(Engine.keys.LEFT ARROW)) this. config.x distance this.setMoving(true) this.setDir(0) if(Engine.input().isPressed(Engine.keys.RIGHT ARROW)) this. config.x distance this.setMoving(true) this.setDir(1) if(Engine.input().isPressed(Engine.keys.UP ARROW)) this. config.y distance this.setMoving(true) this.setDir(2) if(Engine.input().isPressed(Engine.keys.DOWN ARROW)) this. config.y distance this.setMoving(true) this.setDir(3) this.boundaries() As the distance is not 1 pixel, it will be checking a few pixels ahead of the Player for solid tiles, and if there is one X many pixels in front of them, they can't move the distance and stop. Problem So let's say the distance is 3. If they're 2 pixels from a Solid Tile, they will not move those 2 pixels because of the collision detection, meaning there will be a 2 pixel gap between the Player and the tile, which will only increase the larger the Player, or Entities, speed. Is there any way to get around this, other than having to check pixel by pixel for each anchor point I want to check collision on? Collision Detection collided function(box1, box2) Basic Quad intersection Collision return ( ( (box1.x gt box2.x amp amp box1.x lt (box2.x box2.width) ) ( (box1.x box1.width) gt box2.x amp amp (box1.x box1.width) lt (box2.x box2.width) ) ) amp amp ( (box1.y gt box2.y amp amp box1.y lt (box2.y box2.height) ) ( (box1.y h1) gt box2.y amp amp (box1.y h1) lt (box2.y box2.height) ) ) ) ? true false ,


Collision detection, stop gravity I just started using Gamemaker Studio and so far it seems fairly intuitive. However, I set a room to "Room is Physics World" and set gravity to 10. I then enabled physics on my player object and created a block object to match a platform on my background sprite. I set up a Collision Detection event for the player and the block objects that sets the gravity to 0 (and even sets the vspeed to 0). I also put a notification in the collision event and I don't get that either. I have my key down and key up events working well, moving the player left and right and changing the sprites appropriately, so I think I understand the event system. I must just be missing something simple with the physics. I've tried making both and neither of the objects "solid". Pretty frustrating since it looks so easy. The player starting point is directly above the block object in the grid and the player does fall through the block. I even made the block sprite solid red so I could see it (initially it was invisible, obviously).