Is it possible to have concurrent collision detection where every entity acts at exactly the same time? There are many algorithms that can be used for collision detection. In many cases we check for an overlap in coordinates of an entity. If we make a triangle a,b and c. We have 2 entities at a and b heading for a collision at c but each of them are moving at exactly the same time, what kind of algorithm could work? It seems more like a chess game where you would have to predict every move that the other entity would have to make, if they swerve to the left to avoid a collision will they also run the chance to collide. Is it possible or is it too complex? Would it work for thousands and millions of entities in the same search space?


3D collision physics. Response when hitting wall, floor or roof I am having problem with the most basic physic response when the player collide with static wall, floor or roof. I have a simple 3D maze, true means solid while false means air bool bMap 100 100 100 The player is a sphere. I have keys for moving x , x , y , y and diagonal at speed 0.1f (0.1 ftime). The player can also jump. And there is gravity pulling the player down. Relative movement is saved in relx, rely and relz. One solid cube on the map is exactly 1.0f width, height and depth. The problem I have is to adjust the player position when colliding with solids, I don't want it to bounce or anything like that, just stop. But if moving diagonal left up and hitting solid up, the player should continue moving left, sliding along the wall. Before moving the player I save the old player position oxpos xpos oypos ypos ozpos zpos vec3 direction direction vec3(relx, rely, relz) xpos direction.x ftime ypos direction.y ftime zpos direction.z ftime gx floor(xpos 0.25) gy floor(ypos 0.25) gz floor(zpos 0.25) if (bMap gx gy gz true) vec3 normal vec3(0.0, 0.0, 1.0) lt Problem. vec3 invNormal vec3( normal.x, normal.y, normal.z) length(direction normal) vec3 wallDir direction invNormal xpos oxpos wallDir.x ypos oypos wallDir.y zpos ozpos wallDir.z The problem with my version is that I do not know how to chose the correct normal for the cube side. I only have the bool array to look at, nothing else. One theory I have is to use old values of gx, gy and gz, but I do not know have to use them to calculate the correct cube side normal.


LWJGL Collision Detection I cannot find LWJGL collision detection with a camera and walls. Like making it to where you can not walk through walls and other different shaped rectangular prisms and cubes. How do I set up LWJGL collision?


How to build bullet (hit) damage detection in Augmented Reality to a real life person acting as an opponent? I am building an Android AR game using ARcore 1.18 in Unity 2019.4.5f1 (LTS). Now I want to create something like bullet damage detection just like it is built in a normal Unity 3D game. Of course, the biggest problem is how can I even detect the real person's hitbox like it is done in a normal game? I need to somehow be able to attach the bullet damage script to the body of the real life person in real time. Has anyone tried this before? How can we achieve this? I understand if I might not get a spoonfed tutorial but some help towards what should I be doing to achieve this will be greatly appreciated. I see some other FPS Augmented Reality games which either uses Laser Tag (Father.io) or Barcodes to scan the opponents. These are definitely some great ideas to create an FPS game experience but still, if possible, I want to try it with just the mobile camera without any external support. I am ready to bear some accuracy loss )


LibGDX obstacle collision How can I handle collisions with obstacles in LibGDX? Is there any automatic way to stop the character's movement when it collides with a wall or I have to constantly poll for all the possible objects it might encounter and stop the movement accordingly? Polling this way seems pretty poor performance wise, especially if the framework already does that for me and I make no use of it. My game is a top view roguelike, more or less like "The Binding of Isaac". EDIT some beginners like me might make good use of it. Since LibGDX has no built in collision detection without Box2D, for games where physic calculation is not needed you can build your system as follows Create 3 lists (Static, Dynamic, Controlled) where you put all your (relatively inherited) objects in the scene. Static objects (walls, obstacles, traps) are passive and perform no checks. Dynamic objects (projectiles) perform checks on both Static (stop if you hit a wall, destroy self) and Controlled (deal damage) Controlled (players, enemies) objects perform checks on self (player hit AI controlled enemy) and static objects After a collision is reported notify the relative objects. Controlled objects can be Dynamic aswell but if you have a lot of projectiles flying around you can avoid self checking Dynamics and improve the performance. This way you should reduce a lot of useless checks aswell as limit cross checks (both player and projectile notifying eachother) and keep your game well organized. This is just an idea that i'm testing now, I can't guarantee it's the best P


how get collision callback of two specific objects using bullet physics? I have got problem implementing collision callback into my project. I would like to have detection between two specific objects. I have got normall collision but I want one object to stop or change color or whatever when colides with another. I wrote code from bullet wiki int numManifolds dynamicsWorld gt getDispatcher() gt getNumManifolds() for (int i 0 i lt numManifolds i ) btPersistentManifold contactManifold dynamicsWorld gt getDispatcher() gt getManifoldByIndexInternal(i) btCollisionObject obA static cast lt btCollisionObject gt (contactManifold gt getBody0()) btCollisionObject obB static cast lt btCollisionObject gt (contactManifold gt getBody1()) int numContacts contactManifold gt getNumContacts() for (int j 0 j lt numContacts j ) btManifoldPoint amp pt contactManifold gt getContactPoint(j) if (pt.getDistance() lt 0.f) const btVector3 amp ptA pt.getPositionWorldOnA() const btVector3 amp ptB pt.getPositionWorldOnB() const btVector3 amp normalOnB pt.m normalWorldOnB bool x (ContactProcessedCallback)(pt,fallRigidBody,earthRigidBody) if(x) printf("collision n") where fallRigidBody is a dynamic body a sphere and earthRigiBody is static body StaticPlaneShape and sphere isn't touching earthRigidBody all the time. I have got also other objects that are colliding with sphere and it works fine. But the program detects collision all the time. It doesn't matter if the objects are or aren't colliding. I have also added after declarations of rigid body earthRigidBody gt setCollisionFlags(earthRigidBody gt getCollisionFlags() btCollisionObject CF CUSTOM MATERIAL CALLBACK) fallRigidBody gt setCollisionFlags(fallRigidBody gt getCollisionFlags() btCollisionObject CF CUSTOM MATERIAL CALLBACK) So can someone tell me what I am doing wrong? Maybe it is something simple?


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.


Best Efficient way to implement a 3d Collision I've already programmed a 2d based collision system for a previous game. It was my first collision system and it was ugly. I was looking for collision between objects by checking all objects with all objects. I've already heard about a grid system with cells where an object will only look the collision with other objects from its current cell(s). Is it really a good way to check collision? I'd like to have a good technique to loop trough all my items in a 3d world.


Finding collision point of moving projectile bullet with a cube I am programming a game in the spirit of Wolfenstein 3D (2D grid map, 1 cell 1 cube) and I wanted to implement shootings. I didn't want the shootings to happen in one frame so, I wanted to see the beams flying everywhere. So this gets a bit complicated for me to test for impacts. To be fair, I'm not really sure how I'm supposed This is how I used to do it I took the position of the beam and checked on the map to see if there is a wall at said position. It works great when the beam is moving very slowly. But when they go extremely fast, naturally, as you would expect, they clip through walls. Here you can have an idea of what I'm looking for. 2D grid with white cells being air and grey cells being walls. Player is green, beam is red and dotted lines represent the beam on next frames. And orange is the collision So I'm not exactly sure when and what to test for collisions here, as well as how to find the impact's position. What would be the most optimised way to test for collisions ?


How do I compute the point of a triangle ray intersection? I have a line (the direction vector of the player) and a triangle representing the face of a model (so composed of 3 points). I can't find the mathematical operation to check if that vector is intersecting with this triangle, and how far from the player...


Collision for mobile game I'm writing a little game in as3 using Starling, and I need to check collision between 2 boats that can rotate. I don't need the pixel perfect collision, but bounds collision is not enough too. The boat look more or less like this I was thinking about create one square on the back of the boat and a triangle on the front, than for each boat, check if the square collide with the other boat square or triangle, and the same for the triangle. I just don't know how to do that, I don't know if it's possible with the Shape.hitTest, or if it's the best way to do that. What can I do?


How to resolve collision when both of the intersecting bodies were moving? Suppose there are two quadrilaterals A and B. A is stationary but B is moving. They collided. Now B is inside A. To check if they are intersecting I can use 2d separating axis theorem (SAT). To push B out of A so that they are not intersecting anymore, I can again use SAT to get the Minimum Translation Vector(MTV) and project B out of A using it. My problem is, what should I do when both A and B were moving, and then they collided? I can't project A out of B or B out of A alone since both of them were moving. How should I separate them?


Unity3D collider performances on mobile iOS devices I'm experimenting with Unity3D and colliders. Unfortunately I still don't have Unity Pro version and I can't use the profiler. Consider the following situation mobile devices (ios, iphone 3GS). an infinite runner game (consider something like agent dash or temple run). The player run along its path collecting bonuses and possibly hurting obstacles. the number of objects along player's path is very high. The first simple approach is to use a rigidbody with a collider attached to the player (let's say it could be even a shere collider) and use a collider for each object in the scene (coins, obstacles, bonuses,...) . AFAIK, using hundreds of colliders could have a serious impact on performances,specially on mobile devices, am I right? So here's some questions In the situation described above, is that feasible use collider to detect objects collectable by a player running along a path? Could be a better idea to store the location of the collectables objects inside some kind of data structure and completely avoid to use Unity collision detection? What's a reasonable average number of RigidBody Sphere Collider that can be used in a single scene on a mobile device? Does anyone has implemented something similar? Could you suggest me the right way to go?


Retreive 3d World Map coordinates from touch click input with LIBGDX? Problem I am trying to create an RTS style interaction. I want to be able to click on the map and have characters move to the click location. I haven't been able to figure this out, even after reveiwing tutorials from the one and only xoppa and several other's inqueries on the same concept. Other's seem to be happy utilizing collision with a near or far plane or a basic collision shape. However, I have a map with variations in height. I can't tell if I'm not creating my complex collision shape correctly or I'm just making things more complicated than need be. The code I think is relevelvant is as follows. A model is loaded from a G3DB scene in the exact same manner of xoppa loading a 3d scene tutorial. After loading, I call the following method in my ModelInstance class. private Array lt Mesh gt modMesh new Array lt gt () public void createShape() modMesh model.meshes When a user clicks the mouse or taps the touch screen, I call this method to check collision of the ray from the camera to presumably the part of the map we were trying to touch. public Vector3 checkSelection(Ray ray) Vector3 intersection new Vector3() for(int i 0 i lt modMesh.size i ) mesh modMesh.get(i) float v new float mesh.getNumIndices() mesh.getNumVertices() mesh.getVertexSize() short ind new short (mesh.getNumIndices() 6 6) (mesh.getNumVertices() 1) Intersector.intersectRayTriangles(ray, mesh.getVertices(v), ind, mesh.getVertexSize(), intersection) return intersection So, when I run this code, it returns Vector3 values. They seem to be off though. For instance, my camera is looking at point (0,0,0). If I click where (0,0,0) appears on the screen, it will return a value like ( 14.56, 18, 85). I imagine I am not creating a proper collision shape for the map. Which again leads to my question. How do I obtain the collision coordinate on a 3D map with variations in height in LibGDX? Side Note My intersecting collisions with normal collision shapes work perfectly. This is the reason I'm assuming I am completely wrong in the way I create a collision shape for the map itself. Thank you in advance for any input and assistance offered.


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?


Circle inside ellipse collision intersection (preventing circle from leaving the ellipse) I am working on a 2D RPG with a turned based battle system. Characters move inside the confines of an ellipse movement area and when they leave the boundaries will be pushed back inside. (i.e they should be able to walk around the inner part of the ellipse). Previously we were using circles for the movement area and I wrote the code to do circle inside circle collision (not too difficult because the radius is always the same) but since we will change to using an ellipse, I am trying to update the code. I have looked at a few solutions for actual ellipse collision intersection and the math looks..daunting. My questions are Are there any clean solutions to doing circle inside ellipse collision intersection? Should I be approximating the ellipse collision in another way? Like using an n sided polygon? I am a bit lost on how to approach this and could really use some advice.


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


Having issues with pong physics, is my approach wrong? I've been working on a pong clone, i've made games in the past but they have all been very hacky. This time I was trying to go for a better approach in terms of using OOP or patterns. So far the games not posed many issues, I am however having problems thinking about the collision system and ball physics. In my main loop the collision code is as follows if (ball gt Y lt 0) ball gt direction ball gt direction if (ball gt ballSpeed lt 700) ball gt ballSpeed 25 if ((ball gt X ball gt width gt player2 gt X) amp amp (ball gt X ball gt velocityX) (ball gt width) lt player2 gt X player2 gt width amp amp (ball gt Y ball gt velocityY) (ball gt height) gt player2 gt Y amp amp (ball gt Y ball gt velocityY) (ball gt height) lt player2 gt Y player2 gt height) ball gt direction 70 if (ball gt ballSpeed lt 700) ball gt ballSpeed 25 if ((ball gt X ball gt width) gt player1 gt X amp amp (ball gt X ball gt velocityX) (ball gt width) lt player1 gt X player1 gt width amp amp (ball gt Y ball gt velocityY) (ball gt height) gt player1 gt Y amp amp (ball gt Y ball gt velocityY) (ball gt height) lt player1 gt Y player1 gt height) ball gt direction 70 if (ball gt ballSpeed lt 700) ball gt ballSpeed 25 The program checks the points of the objects rect's to see if they have passed any of the paddles and then applies changes to the balls public variables. Here is the ball update code if(move) velocityX int(cos((direction 0.0) M PI 180.0) (ballSpeed deltaTime)) velocityY int(sin((direction 0.0) M PI 180.0) (ballSpeed deltaTime)) rect.x velocityX rect.y velocityY X rect.x Y rect.y width rect.w height rect.h This PARTIALLY works however the ball goes in weird directions sometimes, on top of that the ball can actually go through the bottom portion of the paddle (it seems that from the bottom of the paddle, there is a gap the ball can exactly fit through). Really the physics of the ball just seem weird and not fluid at all. I'm not brilliant at maths so I don't really know of any other way to go about this. Help would be greatly appreciated.


Collision detection circle segment segment I've already implemented collision detection in my game loosely following this tutorial, which works great, but I realized there's one major flaw. The player and the enemies are circles, while the obstacles can be either segments or polygons or circles. Now, let's say I have segment A from point (100, 100) to point (300, 100) and segment B from point (100, 200) to point (300, 100), which means they form an acute angle, and player has it center in point (100, 125), with a radius of 25. If player starts moving right, it will eventually collide against segment B. My method checkCollisions() will return a vector, but if I apply that vector on player, it will be moved up and left, and will overlap segment A. If I call checkCollisions() a second time, player will be pushed down and collide again with segment B, so recursive invocations aren't a solution. Any ideas? Here's a picture to explain The g n vector direction is along the bisector of the two little vectors, but how do I find the length?


How can I implement rectangle collision response? I am working on a game in JavaScript and my current implementation of collision uses the shortest distance to push the intersecting object away, which isn't always correct. I've made this diagram of the ideal collision. The red box represents the starting position, the green box represents the proper position and the black box represents the static object it is colliding against. The blue arrow is the velocity vector. With my current implementation, the object would be placed in its final position and pushed out (and in this case it would be pushed left) How can I fix this?


Can Bullet Physics (or another 3d physics engine) use callbacks in my engine to check static geometry? I'm wondering if it's possible to use or hack Bullet 3d Physics (or another free 3D physics engine) so that I don't need to "import" my static geometry into Bullet instead I want to do it the other way, so Bullet uses some sort of callback system to check geometry properties of my mesh polygons. Sort of like that Bullet would expect a method in my static geometry classes "checkRayIntersection" or similar, and I take care of the details and optimizations myself. The meshes are immovable, so the only thing that I expect Bullet to care about is intersections and their normals, but I might be missing something.. EDIT as an example, consider a 10 million polygon terrain mesh which is changing all the time. You probably don't want to keep parallel data structures in the render engine and in the physics engine for this. You don't want to use an approximation for the physics either. Bullet uses something called MotionStates to solve this problem for its output I was hoping there was a similar design pattern for passing geometry input.


Can GJK be used with the same "direction finding method" every time? In my deliberations on GJK (after watching http mollyrocket.com 849) I came up with the idea that it ins not neccessary to use different methods for getting the new direction in the doSimplex function. E.g. if the point A is closest to the origin, the video author uses the negative position vector AO as the direction in which the next point is searched. If an edge (with A as an endpoint) is closest, he creates a normal vector to this edge, lying in the plane the edge and AO form. If a face is the feature closest to the origin, he uses even another method (which I can't recite from memory right now) However, while thinking about the implementation of GJK in my current came, I noticed that the negative direction vector of the newest simplex point would always make a good direction vector. Of course, the next vertex found by the support function could form a simplex that less likely encases the origin, but I assume it would still work. Since I'm currently experiencing problems with my (yet unfinished) implementation, I wanted to ask whether this method of forming the direction vector is usable or not.


Ground hitting system I want to know how to make character hit ground and lose health. For example when character is falling of one meter he losing only a small part of his health, and when he's falling of 10 metters he dying. I just want to know if it's about speed or distance or maybe even time? (If you can implement some code. please.) P.S. I'm planning to use SFML and C .


Collision in PyGame for spinning rectangular object.touching circles I'm creating a variation of Pong. One of the differences is that I use a rectangular structure as the object which is being bounced around, and I use circles as paddles. So far, all the collision handling I've worked with was using simple math (I wasn't using the collision "feature" in PyGame). The game is contained within a 2 dimensional continuous space. The idea is that the rectangular structure will spin at different speed depending on how far from the center you touch it with the circle. Also, any extremity of the rectangular structure should be able to touch any extremity of the circle. So I need to keep track of where it has been touched on both the circle and the rectangle to figure out the direction it will be bounced to. I intend to have basically 8 possible directions (Up, down, left, right and the half points between each one of those). I can work out the calculation of how the objected will be dislocated once I get the direction it will be dislocated to based on where it has been touch. I also need to keep track of where it has been touched to decide if the rectangular structure will spin clockwise or counter clockwise after it collided. Before I started coding, I read the resources available at the PyGame website on the collision class they have (And its respective functions). I tried to work out the logic of what I was trying to achieve based on those resources and how the game will function. The only thing I could figure out that I could do was to make each one of these objects as a group of rectangular objects, and depending on which rectangle was touched the other would behave accordingly and give the illusion it is a single object. However, not only I don't know if this will work, but I also don't know if it is gonna look convincing based on how PyGame redraws the objects. Is there a way I can use PyGame to handle these collision detections by still having a single object? Can I figure out the point of collision on both objects using functions within PyGame precisely enough to achieve what I'm looking for? P.s I hope the question was specific and clear enough. I apologize if there were any grammar mistakes, English is not my native language.


What is the meaning of this line algorithm? I have been looking at codes of several open source 2d games and I have found this function. GetLineCollisionHit(Vector2 Position1, int Width1, int Height1, Vector2 Position2, int Width2, int Height2) int tile1X Position1.X Width1 16.0) int tile1Y Position1.Y Height1 16.0) int tile2X Position2.X Width2 16.0) int tile2Y Position2.Y Height2 16.0) do int dx Math.Abs(tile1X tile2X) int dy Math.Abs(tile1Y tile2Y) if (tile1X tile2X amp amp tile2Y tile1Y) return true if (dx gt dy) if (tile1X lt tile2X) tile1X else tile1X (check collision) else if (tile1Y lt tile2Y) tile1Y else tile1Y (return true if collision) while (true) return false What is really checking is if there is any collision of solid tiles between two points, for this look for the line between the two tiles. But I do not know if it is a coding problem since it is not implementing neither Bresenham's line algorithm nor DDA or similar. So what are you trying to find in this line dx dy? What sense does it have to advance x while x y since that way a line is not correctly created.


Penetration Depth into a Planar Polygon I'm working on a self made physics engine, and I'm wondering about the best way to calculate the penetration depth into a polygon that lies in a plane given that resolution must occur along the polygon's normal. My current system correctly uses GJK EPA to detect if a polygon that lies in a plane is intersecting a 3D collider. However, in a case such as the one illustrated below, EPA would not calculate the separating axis to be along the plane normal, but rather outwards parallel to the plane, as that is the direction of minimum penetration. My first thought was to simply manually alter the resolution direction. After GJK detects a collision, I can calculate the support mapping of the polygon in the opposite direction of the plane's normal, then take its perpendicular distance from the plane as its penetration depth. However, in a case such as the one below, this would yield an incorrect penetration depth, as the support point does not project onto the plane. What's the best way to go about getting the penetration depth into the polygon, but only considering penetration of points on the polygon that actually project onto the polygon?


Deactivate keyboard input on collision I'm creating an online canvas game with a tank as player object. Now I have several structures in my canvas, that shouldn't be able to be overdriven by the tank... My solution is to detect the collision like that if(hero.x gt reactor i 'x' 32 amp amp hero.x lt reactor i 'x' 32 amp amp hero.y gt reactor i 'y' 32 amp amp hero.y lt reactor i 'y' ) collidetop true if(hero.x gt reactor i 'x' 32 amp amp hero.x lt reactor i 'x' 32 amp amp hero.y gt reactor i 'y' amp amp hero.y lt reactor i 'y' 32) collidebottom true if(hero.x gt reactor i 'x' 32 amp amp hero.x lt reactor i 'x' amp amp hero.y gt reactor i 'y' 32 amp amp hero.y lt reactor i 'y' 32) collideleft true if(hero.x gt reactor i 'x' amp amp hero.x lt reactor i 'x' 32 amp amp hero.y gt reactor i 'y' 32 amp amp hero.y lt reactor i 'y' 32) collideright true The hero object is the tank, hero.x the x coordinate, and so on... Now I'd like to deactivate the keyboard input for the direction key, if the objects collide... For this reason I have the variables wok, aok, sok and dok they all contain booleans. If wok false, then the key "w" is deactivated... I've connected the collide variables to the keyboard inputs if(collidetop true) sok false if(collidetop false) sok true if(collidebottom true) wok false if(collidebottom false) wok true if(collideright true) aok false if(collideright false) aok true if(collideleft true) dok false if(collideleft false) dok true My problem is if the tank doesn't collide the other object any more, the keys stay blocked... Could you help me with that?


How would I move something around inside of a sphere without it going outside of the sphere? I want to be able to do this, but not go outside of the 4.4 meter limit, the radius is 4.4 meters, and it has zero gravity and no friction. I have a hard time explaining this, but imagine holding a hollow sphere with a little ball inside, when you shake it around the ball goes around the inside, I need something like that, but with zero gravity and no friction. I wasn't really sure how to do this, but I tried void Slide() if (slide) for (uint32 t deviceIndex 0 deviceIndex lt vr k unMaxTrackedDeviceCount deviceIndex ) glm vec3 position devicePos deviceIndex .xyz() if (sqrt(pow(position.x 0.35, 2) pow(position.y 1.75, 2) pow(position.z 0.85, 2)) gt 4.4) if (abs(position.x) gt abs(position.y) amp amp abs(position.x) gt abs(position.z)) if (position.x gt 0) velocity.x ((abs(velocity.y)) (abs(velocity.z))) 2 else velocity.x ((abs(velocity.y) 1) (abs(velocity.z) 1)) 2 if (abs(position.y) gt abs(position.x) amp amp abs(position.y) gt abs(position.z)) if (position.y gt 0) velocity.y ((abs(velocity.x)) (abs(velocity.z))) 2 else velocity.y ((abs(velocity.x) 1) (abs(velocity.z) 1)) 2 if (abs(position.z) gt abs(position.x) amp amp abs(position.z) gt abs(position.y)) if (position.z gt 0) velocity.z ((abs(velocity.x)) (abs(velocity.y))) 2 else velocity.z ((abs(velocity.x) 1) (abs(velocity.y) 1)) 2


Detect collision in Blender I am trying to write a Python function for Blender(2.66) game engine, that permits me to detect collision between two objects. I tried to read the documentation, but it's very confusing, and I don't understand it. Someone have an example how to do it?


How to build bullet (hit) damage detection in Augmented Reality to a real life person acting as an opponent? I am building an Android AR game using ARcore 1.18 in Unity 2019.4.5f1 (LTS). Now I want to create something like bullet damage detection just like it is built in a normal Unity 3D game. Of course, the biggest problem is how can I even detect the real person's hitbox like it is done in a normal game? I need to somehow be able to attach the bullet damage script to the body of the real life person in real time. Has anyone tried this before? How can we achieve this? I understand if I might not get a spoonfed tutorial but some help towards what should I be doing to achieve this will be greatly appreciated. I see some other FPS Augmented Reality games which either uses Laser Tag (Father.io) or Barcodes to scan the opponents. These are definitely some great ideas to create an FPS game experience but still, if possible, I want to try it with just the mobile camera without any external support. I am ready to bear some accuracy loss )


Platformer movement and collisions I'm working on a platformer but I'm stuck at the player movement and collisions. Right now I'm not including the grid at all in the movement, but it's time I do it. I've read this article on how to do it. But there's no real code examples just theory. I like the second example and that's the one I'm going for. I want the movement to be smooth, and the player should be able to run in between squares from my map array. This means I have to get tile information from the array, and according to that allow forbid my player to move in that direction. And that's where I'm stuck. My array is a bunch of 1's and 0's right now. I know how to calculate a hitbox around the player, but how do I compare that to the array in an efficiant way? UPDATE I've been playing around with this for a while now, and the only thing I came up with is using player X and Y which is in pixels, dividing by tile size, and getting a rough estimate on the map. Then I make it an AABB by adding its width and height to get the corners. This showed to be very unreliable though, and I would really need some help on how to structure this.


How can I do fast Triangle Square vs Triangle collision detection? I have a game world where the objects are in a grid based environment with the following restrictions. All of the triangles are 45 90 45 triangles that are unit length. They can only rotate 90 . The squares are of unit length and can not rotate (not that it matters) I have the Square vs Square detection down and it is very very solid and very fast (max vs min on x and y values) Wondering if there are any tricks I can employ since I have these restrictions on the triangles?


Basic 3D Collision detection in XNA 4.0 I have a problem with detecting collision between 2 models using BoundingSpheres in XNA 4.0. The code I'm using i very simple private bool IsCollision(Model model1, Matrix world1, Model model2, Matrix world2) for (int meshIndex1 0 meshIndex1 lt model1.Meshes.Count meshIndex1 ) BoundingSphere sphere1 model1.Meshes meshIndex1 .BoundingSphere sphere1 sphere1.Transform(world1) for (int meshIndex2 0 meshIndex2 lt model2.Meshes.Count meshIndex2 ) BoundingSphere sphere2 model2.Meshes meshIndex2 .BoundingSphere sphere2 sphere2.Transform(world2) if (sphere1.Intersects(sphere2)) return true return false The problem I'm getting is that when I call this method from the Update method, the program behaves as if this method always returns true value (which of course is not correct). The code for calling is very simple (although this is only the test code) if (IsCollision(model1, worldModel1, model2, worldModel2)) Window.Title "Intersects" What is causing this? The way Im drawing the scene is to load the number of elements and their coordinates from a file like this (it is called from Update method) OpenFileDialog Otvaranje new OpenFileDialog() if (ks.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.L)) this.GraphicsDevice.Clear(Color.CornflowerBlue) Otvaranje.ShowDialog() try using (StreamReader sr new StreamReader(Otvaranje.FileName)) String linija while ((linija sr.ReadLine()) ! null) red linija.Split(',') model red 0 x red 1 y red 2 z red 3 elementi.Add(Convert.ToInt32(model)) podatci.Add(new Vector3(Convert.ToSingle(x), Convert.ToSingle(y), Convert.ToSinglez))) sfere.Add(new BoundingSphere(new Vector3(Convert.ToSingle(x), Convert.ToSingle(y), Convert.ToSingle(z)), 1f)) And then in the Update() method I had the following code (this was my first attempt) if(sfere.Count ! 0) for(int i 1 i lt sfere.Count i ) if(sfere 0 .Intersects(sfere i )) Window.Title "Intersects" This code never returned that collision is true because the bounding boxes are moving when the box moves, and I don't know why. The code that moves the box is this if (Microsoft.Xna.Framework.Input.ButtonState.Pressed Mouse.GetState().LeftButton) worldKutija Matrix.CreateTranslation(new Vector3(0.01f, 0f, 0f)) worldKutija So if the model is set to be the box it is drawn into the worldKutija, and all other models are drawn into world matrix so they would not move with the box model. So why are their BoundingSpheres moving? After this started happening I tried the code I posted in the original question, and got the problems I was talking about


Collisions between players in multiplayer racing game I'm creating a simple racing game (spaceships, no gravity) using p2.js, phaser and node.js. What I have done Client receives world state from server extrapolate other players based on latest velocity position from server check if client side prediction was correct if no apply position from server and process inputs that server was not aware of. fixed physics step Server receives inputs from clients and apply fixed physics step sends world state to each client Now I'm struggling with collisions between players. Colliding player is jumping all time during collision. I think it's because client side prediction is not calculating similar results to the server. Server doesn't know all inputs from player (lag). Player doesn't have the same position of colliding player as the server (lag). Combining this two makes the client to resolve collision different than the server and when world state arrives player has to make a big correction.


How to make space invaders destructible scenery and conform it to a shape? We all like the bases that can be destroyed by chunks being split out, I originally implemented it by making a rectangle filled with individual squares (2x2 pixel size CANVAS rects) that would collision detect with any bullets (On 2 very inefficient). I am now trying to make the base into a shape instead of a boring rectangle. I also want to perform collections of nearby squares when one is hit so that chunks can be taken of the base, instead of just the part that was hit. (easy to do with a rectangular array) Is a 2 dimensianal arry still the best way to acheive this? Is there a way to create this array by somehow performing image analysis of a PNG to populate this array? Transparent parts would hold no base item at that i j .


Collision handling for grid based games and simulations I'm trying to implement a grid based game where there are many creatures moving in the grid from square to square. I'm having a hard time handling collision with creatures in the grid (multiple creatures trying to move into the same square or cell). Where can I find information on how I should handle a game (or simulation) where multiple creatures in a grid want to move into the same cell but aren't allowed to? It's easy to handle 2 creatures, but handling n object collision is tough. I'm looking for info on how to handle collision in a grid world. I don't expect a specific answer as much as resources or suggestions to find more info. EDIT To clarify, I'm looking for info on HOW TO HANDLE COLLISIONS BETWEEN MULTIPLE OBJECTS IN A GRID. In a grid world where multiple objects want to move into the same cell at the same time, how do I resolve this? Does one object get to move into the cell and the other objects remain stationary? Do I make each object push the other object out of its cell? These are the questions I want to answer. An example of the problem I'm looking to answer Consider a grid where there's 3 creatures who move from tile to tile. What do I do when two creatures, A and B, try moving into the same tile? Let's consider if I allow creature A to move into the tile but creature B remains stationary. What happens if a different creature C wanted to move into the tile that creature B was stuck in? Then creature C also wouldn't be able to move. This would cause an issue if I would evaluate creature C's movement first, telling it that he can move into the tile that creature B is in (because creature B plans to move out) but then creature B ends up never moving out. How do I determine which creatures to evaluate first? Also, how do I avoid this huge chain of creatures being forced to remain stationary (in this example, only 1 3 creatures were able to move).


Resolving collision with multiple objects I already have SAT implemented for collision detection and MTV computation and it works totally fine when my character collides with only one object. But it's possible that there is a collision with multiple objects at once. How do I handle such cases? How do I evaluate chracter translation using all computed MTVs? Pseudocode of how my code currently looks like Contains objects collision with which was detected during broadphase list lt collider gt overlappingObjects Collider for the character for which I'm trying to solve the collision collider characterCollider response res vec3 translation for(collider in overlappingObjects) test if they actally collide and put collision information in res if they do if(testCollision(characterCollider, collider, res)) translation res.mtv Moving character out of the collided objects characterCollider.offset(translation) This code works incorrectly if overlappingObjects contains more than 1 object. What is the correct solution for such problem?


Robust "soft" platform collision using SAT We'll start with the questions, then a pile of background How do you rigorously and thoroughly define "soft collision" of the Mario esque type (if I start above, or in a jump my feet apex above a "soft platform", I'll land on it)? Can you suggest a definition in terms of object versus segment (or line, or ray, or whatever similar terrain boundary), in a SAT framework? Any good examples references for soft collision out there, even in non SAT frameworks? Finally, any edge corner cases, literal or otherwise, that might not be obvious? The background 6 years ago, I built a simple AABB object versus line segment terrain collision system for work, based heavily on N Tutorial A Collision Detection and Response. (This goes against my advice to never write physics collision for production code oneself, but we had strange requirements no FPU, blazingly fast SRAM and bus, and a relatively slow CPU.) Over the years, we've dealt with a number of (sometimes quite literal) "corner cases", including how we deal with fast moving objects (currently very fine grained multisampling), order of collision resolution, et cetera. This is the usual difficult stuff for na ve SAT, it would seem. Recently another issue with our "soft collision" that is, platforms one can jump "up" through, but not fall "down" through (where "up" and "down" are relative to a unit normal off the line segment) has cropped up. This has me wondering if I've "stated the problem" correctly vis a vis soft platforms. As background, the bug in this case involved characters jumping with an arc such that their "head" just hit the bottom of the soft line segment. Our collision system does, roughly early miss if movement.dot( segmentUnitNormal ) gt 0 moving away from segment, for all segments (debatable whether this should be here, but probably largely irrelevant for this problem) normal three axis SAT (x axis, y axis, and line axis) with miss if any axis shows separation compute proposed projection to displace box out of segment if hit late miss unless 0 lt projection.dot( segmentUnitNormal ) lt 1 for "soft" segments only finally, hit Step 3 specifically the 0 part of 0 lt is the issue here. (On the other end of the range, the choice of 1 as cutoff for maximum interpenetration is arbitrary it's based on our multisample worst case projection response.) Amusingly, the comment above step 3 in the code says something like "Miss unless we started 'above' the segment, or if interpenetration is too deep." The logic as stated says nothing about starting above, instead dealing only with response along unit normal. As mentioned, the 0 case here is the issue if the character's "head" hits the segment exactly at the peak of his jump and we compute a zero response, we'll treat that as a hit, when we'd expect to only get hits when our "feet" are at or just above the segment. We could just exclude the 0 case here, and deal with a little "bounce" when resting on our soft platform, but then we'd have strange cases where we might not seem to be in contact with the world geometry every other frame, which has other implications for the animation system and the like. I'd like to preserve 0 interpenetration hit behavior. I have a few possible solutions, mostly boiling down to things like "check if AABB centerpoint started on the correct side of the segment", or "retain the directionality of the projection even if it collapses to zero length" (something like a "signed zero" here we already have this from our SAT calculations earlier), ...coupled with a little more care re whether we're using "computed projection along the line axis" versus "shortest computed projection" in these tests. All of these solutions seem to be robust, in my initial tests. But it has me wondering if I'm missing something obvious hence the questions above.


Applying statements to a single instance in Game Maker? I'm currently in the process of making a platformer, and am currently in the process of creating "depth" into my game, by making Up Down W S control your depth. (Come closer to screen, go further). The reason I chose to do this is so I can walk around stairs, go behind tables, etc. But I have run into a problem. When I call in my player code, if (depth oWall.depth) code , it is applying to every single wall ever. Is there a way to only make it apply to the object you are currently touching? Here is my code so far Collision TODO Make "depth" apply to a singular instance. if (depth oWall.depth) Colliding with a wall on the Horizontal Axis, causes the player to stop moving. if (place meeting(x h speed, y, oWall)) while(!place meeting(x sign(h speed), y, oWall)) x sign(h speed) h speed 0 Colliding with a wall on the Vertical Axis, causes the player to stop moving. if (place meeting(x, y v speed, oWall)) while(!place meeting(x, y sign(v speed), oWall)) y sign(v speed) v speed 0 Hope you understand what I'm asking.


Bounding Box Collision Glitching Problem (Pygame) So far the "Bounding Box" method is the only one that I know. It's efficient enough to deal with simple games. Nevertheless, the game I'm developing is not that simple anymore and for that reason, I've made a simplified example of the problem. (It's worth noticing that I don't have rotating sprites on my game or anything like that. After showing the code, I'll explain better). Here's the whole code from pygame import DONE False screen display.set mode((1024,768)) class Thing() def init (self,x,y,w,h,s,c) self.x x self.y y self.w w self.h h self.s s self.sur Surface((64,48)) draw.rect(self.sur,c,(self.x,self.y,w,h),1) self.sur.fill(c) def draw(self) screen.blit(self.sur,(self.x,self.y)) def move(self,x) if key.get pressed() K w or key.get pressed() K UP if x 1 self.y self.s else self.y self.s if key.get pressed() K s or key.get pressed() K DOWN if x 1 self.y self.s else self.y self.s if key.get pressed() K a or key.get pressed() K LEFT if x 1 self.x self.s else self.x self.s if key.get pressed() K d or key.get pressed() K RIGHT if x 1 self.x self.s else self.x self.s def warp(self) if self.y lt 48 self.y 768 if self.y gt 768 48 self.y 0 if self.x lt 64 self.x 1024 64 if self.x gt 1024 64 self.x 64 r1 Thing(0,0,64,48,1,(0,255,0)) r2 Thing(6 64,6 48,64,48,1,(255,0,0)) while not DONE screen.fill((0,0,0)) r2.draw() r1.draw() If not intersecting, then moves, else, it moves in the opposite direction. if not ((((r1.x r1.w) gt (r2.x r1.s)) and (r1.x lt ((r2.x r2.w) r1.s))) and (((r1.y r1.h) gt (r2.y r1.s)) and (r1.y lt ((r2.y r2.h) r1.s)))) r1.move(1) else r1.move(0) r1.warp() if key.get pressed() K ESCAPE DONE True for ev in event.get() if ev.type QUIT DONE True display.update() quit() The problem In my actual game, the grid is fixed and each tile has 64 by 48 pixels. I know how to deal with collision perfectly if I moved by that size. Nevertheless, obviously, the player moves really fast. In the example, the collision is detected pretty well (Just as I see in many examples throughout the internet). The problem is that if I put the player to move WHEN IS NOT intersecting, then, when it touches the obstacle, it does not move anymore. Giving that problem, I began switching the directions, but then, when it touches and I press the opposite key, it "glitches through". My actual game has many walls, and the player will touch them many times, and I can't afford letting the player go through them. The code problem illustrated When the player goes towards the wall (Fine). When the player goes towards the wall and press the opposite direction. (It glitches through). Here is the logic I've designed before implementing it I don't know any other method, and I really just want to have walls fixed in a grid, but move by 1 or 2 or 3 pixels (Slowly) and have perfect collision without glitching possibilities. What do you suggest?


Given a plane and a point, how can I determine which side of the plane the point is on? Given the point Vector pos new Vector(0.0, 0.20156815648078918, 78.30000305175781, 1.0) and the plane (triangle) Vector a new Vector( 6.599999904632568, 0.0, 78.5, 1.0) Vector b new Vector(6.599999904632568, 0.0, 78.5, 1.0) Vector c new Vector(6.599999904632568, 4.400000095367432, 78.5, 1.0) I want to get a plane normal pointing in the direction of pos Getting plane normal Vector ac Vector.Subtract(a,c) Vector bc Vector.Subtract(b,c) Vector planeNormal Vector.CrossProduct(bc, ac) Testing which side of the plane the point is on double dprod Vector.DotProduct(planeNormal, pos) if (dprod lt 0) planeNormal.Negate() But this method is wrong. The resulting planeNormal points in the negative Z direction, so it should not be negated. Is there a best practise for this? Please help me, I fail massively math )


Using PhysX, how can I predict where I will need to generate procedural terrain collision shapes? In this situation, I have terrain height values I generate procedurally. For rendering, I use the camera's position to generate an appropriate sized height map. For collision, however, I need to have height fields generated in areas where objects may intersect. My current potential solution, which may be naive, is to iterate over all "awake" physics actors, use their bounds extents and velocities to generate spheres in which they may reside after a physics update, then generate height values for ranges encompassing clustered groups of actors. Much of that data is likely already calculated by PhysX already, however. Is there some API, maybe a set of queries, even callbacks from the spatial system, that I could use to predict where terrain height values will be needed?


Should I use Box2D for collision detection only (not simulating physics)? I'm using Box2D only to check collisions and for no physical simulation. I create bodies (and shapes for them) and use my own code to move them, by setting their velocities and positions every frame. I only fetch collision data from the Box2D world. Is this a good idea? For example, can it cause undefined behaviour from Box2D? Is there a more performance friendly way of dealing with different shape collision detections? Do better methods exist for this?


How do I detect a line collison in LIBGDX? I am drawing a continuous line using Pixmap. I want to check for a collision intersection of my line with the already drawn line.


How do I determine if one polygon completely contains another? I have 2 polygons. I know the vertex coordinates of both polygons. What's the best way to check if one is completely inside the other? For example, the algorithm should only recognize the black trapezoid below as being contained


2D Collision detection and design So, listening to this very smart piece of advice, I've already completed a basic Tetris game. Moving on, I started a small breakout. But suddenly a nightmare came. Collisions. Since I've been struggling with this a lot, I read a bunch of article of the web. Being a beginner, I thought that, in the first approach, I would only use Rectangle to detect collisions. Right. Now I still have some problems. First of all, all the articles I stumbled upon on the Internet told me how to detect collisions, e.g. checking if objects A and B collided with each other. But it is not what I really need. In order to respond properly, I need to tell my objects if the collision happened on the X or Y axis and then setting the new velocity according to some rules. The problem is that there are so many possibilities when making the distinction between types of collisions that I don't think I've taken the right path. The second point (which, I believe, is really tied with the first) is the pattern in which the detection and the resolution of a collision happen. Right now, I have a CollidableObject classes and a CollisionDetector classes which knows about these objects. Each frame, the detector is looking for collision (or at least for me, is trying) and when he finds one, it alerts each collided object, saying "Hey you ! You've have collided with Z on the X axis, change that velocity now." and the object abides. The main issue right now is that I can detect the collision axis and therefore, when saying "Hey you ! You collided !", I cannot respond properly. In which direction should my velocity change ? I've been thinking a lot about this lately, trying to figure it out on my own, but I haven't find something that I liked so I am asking here now. Thank you for your answers ! (Note I don't know if this is relevant, but I'm coding in C using SDL)


3D models and hit detection I'm currently trying to create a game that involves the inside of a cube, which i will make in Maya. My question is what is the best way to create a model with hit detection in mind? For example my model will be a cube that you can walk inside of, so should i make the cube as a one model or make one wall and put it together inside XNA? The reason I ask this is because I'm sure that if I create a whole cube and then use XNA's bounding rectangle method, hit detection will always be true because the bounding rectangle will encompass the whole cube, making collision detection inside the cube non existent without the use of hard values. Whereas separate walls would make the process easier because i will checking against separate walls instead of the whole thing. To add to the problem, I also have doors in the walls so hit detection for the walls in that area need to be turned off. What is the best way to do this?


Exact collision detection for high detail deformable triangular meshes What robust methods or approaches exist for exact collision detection involving high detail, deformable geometry? The kind of mesh I am describing is a surface that is specified as a triangulated polyhedron and looks very similar to this For the specific application I am working on, I need to find all the contact points for colliding meshes that undergo subsequent deformation. Possible deformations that may occur during a collisional event 1) the mesh decomposes, or fragments into smaller (triangulated) meshes 2) the mesh retains integrity but the vertex values of it's surface change 3) both of the above deformations occur There is no real time constraint accuracy rather than performance is the critical factor.


TileMap or Voxel collision detection I have a conceptual question In the case of Tile Map, each block has the information from the enemies who are going about it. But what if some of these enemies are far greater than the block? I have to have the same element in each of the information blocks? And updating the position must clear each block? If I have large and small enemies, it means that each block will have a list of enemies? Now, in the case of Voxel Map In Minecraft, for example, its character and most enemies x and z dimensions is smaller than one block, but its height (y) is greater than one block. This means that these elements will record information in two blocks? and in the case of a "Gast," which is much larger? I'm using Google Translate, so sorry if my english is very bad. Thanks in advance.


multiple contacts for SAT collision detection I have implemented SAT algorithm for obb obb intersection and I am able to generate a contact for this collision type. My problem is that SAT only generate ONE contact and in many situation I need more than one contact. For example, If I have a big cube and above it I have a small cube I need two contact (two contacts in 2D and 4 contacts in 3D) one for each bottom vertex of small cube. My question is how can I generate more than one contacts with SAT? Thanks.


Is an extra collision mesh for level data worth the hassle? What is the optimal approach for collision detection with the environment in an 3D engine (with triangle mesh based geometry, no bsp)? A) Use the render mesh no need for additional work for artists to fiddle with collision detection high detail is harder for physics calculation maybe use collidable flags for materials compute the collision mesh from the render mesh B) Use an additional collision mesh faster more optimal collision detection additional work (either by the artist or by the programmer who has to develop an algorithm to compute it from the render mesh) more memory useage How do AAA title handle this? And what are the indie dev's approaches?


Handle floating point precision errors in collision detection and resolution I am experimenting with a continuous collision detection and response of points on a tile map. This are my results for now I did this by shooting a ray (red line) from the current position (red circle) to the target position (green circle) and check all tiles which are on it using this algorithm. If the ray hits a solid tile I calculate the exact postion of the collision (yellow circle) and a new target positition depending whether the ray hit the solid tile vertically or horizontally in the other case I can simply set the current position to the target position and be finished because no collision occurred. Now I am shooting a second ray (blue line) to this new target position and check again for solid tiles on it. If a collision occurerd I set the current position to the ray hit position (cyan circle) and be finished. In the other case I only set the the current position to the new target position (cyan circle) because no collision occurred this time. Here the most important source code void update(float start x, float start y, float target x, float target y, float corrected x, float corrected y) float hit0 x float hit0 y LineTraceResult res0 line trace(start x, start y, target x, target y, amp hit0 x, amp hit0 y) switch (res0) case LINE TRACE NONE No collision occurred so the target position is valid and we can move to it. corrected x target x corrected y target y break case LINE TRACE VERT We hit a solid tile on the vertical edge. corrected x hit0 x corrected y target y float hit1 x float hit1 y LineTraceResult res1 line trace(hit0 x, hit0 y, corrected x, corrected y, amp hit1 x, amp hit1 y) if (res1 ! LINE TRACE NONE) There was a second collision on the corrected position so we need to adjust it. Because the x axis did not changed we don't need to change it. corrected y hit1 y break case LINE TRACE HORI We hit a solid tile on the horizontal edge. corrected x target x corrected y hit0 y float hit1 x float hit1 y LineTraceResult res1 line trace(hit0 x, hit0 y, corrected x, corrected y, amp hit1 x, amp hit1 y) if (res1 ! LINE TRACE NONE) There was a second collision on the corrected position so we need to adjust it. Because the y axis did not changed we don't need to change it. corrected x hit1 x break So in theory this all works great but in practice there are a lot of problems caused by the limited precision of floats. For example in this two cases One approach to "solve" this problem is to add some kind of padding often named Epsilon every time a collision occurs but this method seems to me not very accurate and dirty. So I am wondering how all the professional game developers are solving this kind of problem? EDIT This problems occurre because the hit position calculated by the ray can not be 100 exact so it could be for example that the y coordinate gets rounded from 6.9999 to 7.0001 and 6.9999 means tile 6 and 7.0001 means tile 7 so its a huge difference.


How do I resolve a collision of a circle with two rectangle corners? I'm writing a simple non physical one circle to many rectangles collision detector resolver. For collision detection, I'm using a very common algorithm, and it's working pretty well. For collision resolving, once a collision is detected, I calculate the penetration vector, and reactively move the circle in the opposite direction. Once again, it is working pretty well. However, when there are two adjacent colliders, and the circle is moving right in the place where the two colliders meet, the situation is more complex. This is a screenshot of the situation The white rectangles are the rectangle colliders (walls), the yellow circle is the circle collider (player), and the magenta lines are the vectors from the center of the circle to the closest point in each collider. The problem happens when I get a collision on more than one rectangle. As you can see in the picture above, the top rectangle will have a penetration vector which is not in the direction of the normal of the entire surface, and as such will create artifacts as the circle slides through the wall, depending on how I handle it. There are many solutions I have tried, but they all create artifacts. In particular, using any algorithm to pick only one collision and solving only for that one, may yield different solutions depending on the order in which they are evaluated, especially on cases where both collisions must clearly be chosen, like the following one Just for reference, these diagrams are meant to show a top down, not a side view of the playing field. Is there a known way to resolve such a collision correctly?


How to detect collision on specific part of the sprite node I have a spike and a ball is falling down, when the ball touches the top point of the spike, I want to make the ball invisible, and when it touches on the other part i.e on the sides I don't want to make it invisible. I have two sprite nodes Ball and spike. How can I make the collision detect only on specific part i.e only on top of the spike in spritekit?


Collision detection between 2 irregular shapes I need to implement a collision system for a vertical shotter and the bullets can have any type of shape i've implemented the shape class with an array of choords and an array of lines which have the references of start and end points in case the line is bezier it have an array of anchor points. so Line Choord Start,End Choord Anchors null ... Choord float X, Y ... Shape Choord Vertexs Line Lines ... i have to handle a collision like this anyone have a general idea for check collision with this type of shapes? and this model can work? i've tryed with SAT collisions but it works only for convex polygons.


Collision Detection in a big map? So I've been wondering lately... on games like pokemon (on ds and gba), How did they handle the collision of all those tiles in the map? Should all those collision checks running in the background slow down the game? Do they have it where the collision activates from a certain distance? Do they have a player event where the player is next to a tile that is not able to be walked on? If it is not possible to know the answer, could you give me a solution to that problem? I guess what I am really asking is how to handle collision of almost every tile in a big map.


How do I do 3d collisions in isometric game? I've wondered how to get basic collision detection working in an isometric game. I'm using panda3d which has very comfortable support for bullet, ode and a small builtin physics framework. The problem is that these naturally don't work with flat images. I'm using dynamically generated quads as canvases in the 3d coordinate system. Every image or texture is mapped on one of these. The idea is to create tiles with images and place them in 3 dimensions to let panda3d do the rendering. In order to place a tree on the screen I would generate one of the dynamic flat quads and map a texture with an image of the tree on it. Then I would move the quad to the desired position and everything's fine. Panda3d manages the correct rendering order. Up to now the player object simply walks through the environment. I need to implement basic collision detection in order to solidify the trees. Browsing through previous questions I've found this one How do I handle Isometric collision detection? Unfortunately the question only targeted collisions to prevent the player from falling through the ground and allowing him to jump on platforms. This can be done comfortably with panda3d's builtin physics. Here's a picture to show you what I want The ground itself is composed of a 10x10 grid of tiles. I've used the same texture for all of them. The tree is not a sprite that's rendered in 2d. It's actually a flat rectangle with a partially transparent tree texture. The white rectangle is my player object. With the standard 3d physics I could prevent the player from walking through the quad but the tree would still be perfectly flat. I thought about adding a "dummy mesh" to have 3d collisions but that would surely come pricey in terms of performance and would spoil the neat implementation of my 3d canvases. Is there a canonical way to get 3d collisions in an isometric game ? How would you do this ? Please answer this second question on behalf of panda3d. I know that this is probably rather complicated. A link to a good article would be perfect. If you want to have a look at my code, you might want to read this question How do I use setFilmSize in panda3d to achieve the correct view? UPDATE Here's another picture that might depict the problem better


Collision response callback First at all, I'm not asking how to handle or detect collision. I already have that. My actual situation is, I have a system collision and I detect the collisions. Every collision detected is store as a message containing the two entities colliding with some information like type of collision or something. Later, all messages is processed. I'm trying to figure out how to implement the reaction of the entities in every collision with that message. In the game a collision can trigger an action like talking with another, change the level, kill the character, store an object, not letting go... I don't want to hard code the calls and methods if possible (in my ideal world,I can define even the behaviour in an xml an read from that!). My first approach is a class where I store a list of possible actions callback functions and attach it to the entity as a component. When a collision succed, I go to the entity and depending of the collision, execute the correspond callback. Still I don't know how to determine the callback to execute or where I must code the behaviour. Any ideas? What you think about this approach? By the way, I'm building everything from scratch, with c and SFML and following the entity system approach, for educational purpose.


When should you check collisions? Suppose a basic game with several circles drawn to screen. The user can select and drag any ball and move it around the screen. Should the selected ball overlap with any other ball on screen, the other ball should displace so they are no longer touching. The example I've seen use the following structure for (every ball pair) if (collision true) resolve collision However, with this method, isn't there a risk that a displacement could cause an overlap in a pair already checked, and therefore the overlap printed to the screen? Would it not be better to re check every ball pair's collision, every time a ball is displaced, rather than every time step? Maybe something like for (every ball pair) if (collision true) resolve collision for (every ball pair) if (collision true) resolve collision EDIT Even the method I've listed above shouldn't always provide 100 accurate results. The only way I can think this could work is with some sort of recursive function which only stops when there are no more collisions. Does that seem right?


LWJGL Collision Detection I cannot find LWJGL collision detection with a camera and walls. Like making it to where you can not walk through walls and other different shaped rectangular prisms and cubes. How do I set up LWJGL collision?


Collision detection a bunch of special cases? I'm writing a simple physics engine in 2D. My first goal is to get collision detection working. I know that my objects will eventually be made up of primitive shapes, but I was wondering would a collision detection library be composed of a bunch of special case functions, like "rayAndLine", "rectangleRectangle", "rectangleCircle" etc, or is there a common, underlying framework for collision detection that works regardless of which primitives are used to make the shape?


Navigate multiple Units on a grid through a tight space with different directions I just started learning about pathfinding algorithms. Assume we have this scenario Blue and Green can move only on those tiles. They can also talk to each other. Blue wants to go through the tunnel and green wants to go too, however both need to pass each other somehow. In case of a "basic" A pathfinding algorithm they will both get stuck in the tunnel. To prevent this issue i had some Ideas Blue can tell green that he should move back first (give blue priority) when they both step next to each other (problems arise when there are more than 2) A better algorithm, that calculates this like an automatic traffic regulator (one will wait till the other frees the path) seems complicated Now I am wondering if there are more efficient methods, how its done in general, if you have better ideas, if you can point me to some algorithms or some papers that adress this issue.


Collision detection Swinging bat racket and ball I am programming a side view tennis game, inspired by an old arcade game, using Javscript and HTML5 canvas elements. The player can move left and right and holds a racket at arms length which can be rotated 360 degrees around the shoulder joint. I am quite happy with the collision detection and resulting deflection angle between the racket and the ball in the case where the player stands still and the racket does not move. I use a ray casting approach for this collision detection between the vector that represents the racket and the trajectory vector for the ball as proposed here. However, I am having trouble implementing the collision detection between the rotating racket and the ball. When the racket is swung, the area in which a collision would apply has a shape similar to a circular segment , but the racket rotates rotates to fast and the collision detection does not pick it up in most cases. The image bellow illustrates the problem, the red arrow indicates the direction of the swinging racket. The following code snippet from the player entity's update function shows how the racket is updated. arcmx and armcy is the location of the shoulder joint, rstart and rend are the beginning and end of the racket. if(KEY STATUS.rleft KEY STATUS.rright) if(KEY STATUS.rright) this.rangle this.rspeed else if (KEY STATUS.rleft) this.rangle this.rspeed this.armcx this.x this.width 2 this.armcy this.y 46 this.rstartx this.armcx Math.cos(this.rangle) 40 this.rstarty this.armcy Math.sin(this.rangle) 40 this.rendx this.armcx Math.cos(this.rangle) 71 this.rendy this.armcy Math.sin(this.rangle) 71 I am pretty lost on this problem and appreciate any hints on how to approach it.


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 detection against complex shapes and curves I am new in game development and for simple games bounding box collision is fine. However, let's say you have a shape or bitmap like this This is just an example but if you had more elaborate curves or even a whole shape which was more complex than a simple polygon or rectangle like shape, how would you do precise collision detection? I am strictly speaking in 2D here. I just want to know the concept behind how you would do this.


What are "distance fields" and how are they applicable to collision detection? I was looking at some efficient methods for collision detection in a scene with both static and dynamic objects when I came across "distance fields." I tried to search and understand this concept, but I could only find papers written in very complex language. Can someone explain in easy words what distance fields are and how can they be used for collision detection?


Line Rectangle Collision Detection and Response I've looked through Google and none of the solutions seem to pinpoint my idea. Ultimately, I want to create a level editor where I can draw lines and have them exported to a file for my engine to read. I'm having trouble getting path rectangle to work. I'm using this in the context of a platformer, so I'm also interested in knowing which direction and distance the collision came from so I can resolve it. Which is the best algorithm for doing this? I'm only concerned about axis aligned rectangles. EDIT My character is represented as a rectangle and the level is represented by lines. The tools really do not matter as I'm looking for the mathematics behind it, not necessarily an implementation.


Get normal dependent on collisions position As I hask ask here I'm working on how my objects can move over the terrain and other objects. My proposal and also an idea in the answers was to calculate the rotation from the object with the normals from other objects around (under and in front) the moving object. My main problem for that is how I can get the normal from an object at a special position. Let's take the ramp on the road from the old example. It depends from which side my car comes. If it comes from front it can drive along the ramp but if it comes from back it moves against the wall. Of course there are other normals if I come from the other side. All my objects have these variables float vertices float normals short drawOrder float modelMatrix AABBox boundingBox So you see I can allways get the vertices, normals and the position. I can also test if the object collides with another object with the bounding box (axis aligned) but I have no idea how I can get the normal where the collision happens but that is the important thing for the rotation of the car. Do you have any ideas or are there usual way how to do this?


How can I determine which direction a 2D collision is occurring from? The problem is as follows Think 2D Zelda (Links Awakening, A Link to the Past) style movement where you can run into walls from any of the four cardinal directions, or basically up, down, left, and right. The difference between my movement and these games is I want to allow for diagonal movement as well. When the player collides with a wall on the left, for example, if he is pushing left and up I want him to stop moving left but continue moving up. The problem I am having is my code currently detects the collision as both an upwards and a left collision so the player simply stops. What is the approach I should take to remedy this? bool canCollideLeft false bool canCollideRight false bool canCollideUp false bool canCollideDown false if (HeroRect.Left gt OldHeroRect.Left) canCollideLeft false canCollideRight true if (HeroRect.Left lt OldHeroRect.Left) canCollideLeft true canCollideRight false if (HeroRect.Bottom gt OldHeroRect.Bottom) canCollideUp false canCollideDown true if (HeroRect.Bottom lt OldHeroRect.Bottom) canCollideUp true canCollideDown false foreach (RectangleItemProperties rectangle in CollisionRectangles) Rectangle CollisionRect new Rectangle((int)rectangle.Position.X, (int)rectangle.Position.Y, (int)Math.Abs(rectangle.Width), (int)Math.Abs(rectangle.Height)) if (HeroRect.Intersects(CollisionRect)) if (canCollideDown amp amp HeroRect.Bottom gt CollisionRect.Top amp amp HeroRect.Bottom lt CollisionRect.Bottom) hero.position.Y OldHeroRect.Location.Y if (canCollideUp amp amp HeroRect.Top gt CollisionRect.Top amp amp HeroRect.Top lt CollisionRect.Bottom) hero.position.Y OldHeroRect.Location.Y if (canCollideLeft amp amp HeroRect.Left lt CollisionRect.Right amp amp HeroRect.Left gt CollisionRect.Left) hero.position.X OldHeroRect.Location.X if (canCollideRight amp amp HeroRect.Right gt CollisionRect.Left amp amp HeroRect.Right lt CollisionRect.Right ) hero.position.X OldHeroRect.Location.X In summary the code compares the old position with the new position to see which direction we have moved and checks for a potential collision there. So if we move up and to the left, canCollideLeft and canCollideUp will be true. I am pretty sure this is where my problem lies and I need to better check which direction I am colliding from. Any thoughts or insight?


Collision detection via adjacent tiles sprite too big I have managed to create a collision detection system for my tile based jump'n'run game (written in C SFML), where I check on each update what values the surrounding tiles of the player contain and then I let the player move accordingly (i. e. move left when there is an obstacle on the right side). This works fine when the player sprite is not too big Given a tile size of 5x5 pixels, my solution worked quite fine with a spritesize of 3x4 and 5x5 pixels. My problem is that I actually need the player to be quite gigantic (34x70 pixels given the same tilesize). When I try this, there seems to be an invisible, notably smaller boundingbox where the player collides with obstacles, the player also seems to shake strongly. Here some images to explain what I mean Works Doesn't work Another example of non functioning (the player isn't falling, he stays there in the corner) My code for getting the surrounding tiles looks like this (I removed some parts to make it better readable) std vector lt std map lt std string, int gt gt Game getSurroundingTiles(sf Vector2f position) converting the pixel coordinates to tilemap coordinates sf Vector2u pPos(static cast lt int gt (position.x tileSize.x), static cast lt int gt (position.y tileSize.y)) std vector lt std map lt std string, int gt gt surroundingTiles for(int i 0 i lt 9 i) calculating the relative position of the surrounding tile(s) int c i 3 int r static cast lt int gt (i 3) we subtract 1 to place the player in the middle of the 3x3 grid sf Vector2u tilePos(pPos.x (c 1), pPos.y (r 1)) this tells us what kind of block this tile is int tGid levelMap tilePos.y tilePos.x converts the coords from tile to world coords sf Vector2u tileRect(tilePos.x 5, tilePos.y 5) storing all the information std map lt std string, int gt tileDict tileDict.insert(std make pair("gid", tGid)) tileDict.insert(std make pair("x", tileRect.x)) tileDict.insert(std make pair("y", tileRect.y)) adding the stored information to our vector surroundingTiles.push back(tileDict) I organise the map so that it is arranged like the following 4 1 5 2 3 6 0 7 return surroundingTiles I then check in a loop through the surrounding tiles, if there is a 1 as gid (indicates obstacle) and then check for intersections with that adjacent tile. The problem I just can't overcome is that I think that I need to store the values of all the adjacent tiles and then check for them. How? And may there be a better solution? Any help is appreciated. P.S. My implementation derives from this blog entry, I mostly just translated it from Objective C Cocos2d.


How collision boxes are assigned to object in 3D games? Level designers make levels and then programmers import the models and use it but How and when collision boxes are generated for objects and models in the 3D map placed at random locations? Thanks.


Should I use Box2D for collision detection only (not simulating physics)? I'm using Box2D only to check collisions and for no physical simulation. I create bodies (and shapes for them) and use my own code to move them, by setting their velocities and positions every frame. I only fetch collision data from the Box2D world. Is this a good idea? For example, can it cause undefined behaviour from Box2D? Is there a more performance friendly way of dealing with different shape collision detections? Do better methods exist for this?


What is the meaning of this line algorithm? I have been looking at codes of several open source 2d games and I have found this function. GetLineCollisionHit(Vector2 Position1, int Width1, int Height1, Vector2 Position2, int Width2, int Height2) int tile1X Position1.X Width1 16.0) int tile1Y Position1.Y Height1 16.0) int tile2X Position2.X Width2 16.0) int tile2Y Position2.Y Height2 16.0) do int dx Math.Abs(tile1X tile2X) int dy Math.Abs(tile1Y tile2Y) if (tile1X tile2X amp amp tile2Y tile1Y) return true if (dx gt dy) if (tile1X lt tile2X) tile1X else tile1X (check collision) else if (tile1Y lt tile2Y) tile1Y else tile1Y (return true if collision) while (true) return false What is really checking is if there is any collision of solid tiles between two points, for this look for the line between the two tiles. But I do not know if it is a coding problem since it is not implementing neither Bresenham's line algorithm nor DDA or similar. So what are you trying to find in this line dx dy? What sense does it have to advance x while x y since that way a line is not correctly created.


What is the best way to check for intersection of two bounding boxes, given a minimum and maximum Vector3 for each one I have a BoundingBox object which holds two Vector3's (x, y, z), one for the minimum point and one for the maximum point. ( 1.5 0 9 1.5 3 10) What is the best way to check for any intersection or overlap of two BoundingBoxes? The test for intersection will happen more often than not when there are no points actually intersecting, just faces. The code that I currently am using is bb1.max .x gt bb2.min .x amp amp bb1.min .x lt bb2.max .x amp amp bb1.max .y gt bb2.min .y amp amp bb1.min .y lt bb2.max .y amp amp bb1.max .z gt bb2.min .z amp amp bb1.min .z lt bb2.max .z However this leads to problems when points are, for example 1.5 0 9 1.5 3 10 intersecting with 0.5 0 8.5 0.5 1.8 10.5... The Z minimum and maximum points for the second object laying entirely outside of the Z min and max for the first object.


Bounding Box Collision Glitching Problem (Pygame) So far the "Bounding Box" method is the only one that I know. It's efficient enough to deal with simple games. Nevertheless, the game I'm developing is not that simple anymore and for that reason, I've made a simplified example of the problem. (It's worth noticing that I don't have rotating sprites on my game or anything like that. After showing the code, I'll explain better). Here's the whole code from pygame import DONE False screen display.set mode((1024,768)) class Thing() def init (self,x,y,w,h,s,c) self.x x self.y y self.w w self.h h self.s s self.sur Surface((64,48)) draw.rect(self.sur,c,(self.x,self.y,w,h),1) self.sur.fill(c) def draw(self) screen.blit(self.sur,(self.x,self.y)) def move(self,x) if key.get pressed() K w or key.get pressed() K UP if x 1 self.y self.s else self.y self.s if key.get pressed() K s or key.get pressed() K DOWN if x 1 self.y self.s else self.y self.s if key.get pressed() K a or key.get pressed() K LEFT if x 1 self.x self.s else self.x self.s if key.get pressed() K d or key.get pressed() K RIGHT if x 1 self.x self.s else self.x self.s def warp(self) if self.y lt 48 self.y 768 if self.y gt 768 48 self.y 0 if self.x lt 64 self.x 1024 64 if self.x gt 1024 64 self.x 64 r1 Thing(0,0,64,48,1,(0,255,0)) r2 Thing(6 64,6 48,64,48,1,(255,0,0)) while not DONE screen.fill((0,0,0)) r2.draw() r1.draw() If not intersecting, then moves, else, it moves in the opposite direction. if not ((((r1.x r1.w) gt (r2.x r1.s)) and (r1.x lt ((r2.x r2.w) r1.s))) and (((r1.y r1.h) gt (r2.y r1.s)) and (r1.y lt ((r2.y r2.h) r1.s)))) r1.move(1) else r1.move(0) r1.warp() if key.get pressed() K ESCAPE DONE True for ev in event.get() if ev.type QUIT DONE True display.update() quit() The problem In my actual game, the grid is fixed and each tile has 64 by 48 pixels. I know how to deal with collision perfectly if I moved by that size. Nevertheless, obviously, the player moves really fast. In the example, the collision is detected pretty well (Just as I see in many examples throughout the internet). The problem is that if I put the player to move WHEN IS NOT intersecting, then, when it touches the obstacle, it does not move anymore. Giving that problem, I began switching the directions, but then, when it touches and I press the opposite key, it "glitches through". My actual game has many walls, and the player will touch them many times, and I can't afford letting the player go through them. The code problem illustrated When the player goes towards the wall (Fine). When the player goes towards the wall and press the opposite direction. (It glitches through). Here is the logic I've designed before implementing it I don't know any other method, and I really just want to have walls fixed in a grid, but move by 1 or 2 or 3 pixels (Slowly) and have perfect collision without glitching possibilities. What do you suggest?


Cocos2d Box2d contact listener call different method in collided object I have the building object, when it collides with another object I want to call some method inside it. Building.mm (void)printTest NSLog( "printTest method work correctly") in my ContactListener I'm trying to call it so ContactListener.mm import "ContactListener.h" import "Building.h" void ContactListener BeginContact(b2Contact contact) b2Body bodyA contact gt GetFixtureA() gt GetBody() b2Body bodyB contact gt GetFixtureB() gt GetBody() Building buildA (Building )bodyA gt GetUserData() Building buildB (Building )bodyB gt GetUserData() if (buildB.tag 1) NSLog( "tag 1") if (buildA.tag 2) NSLog( "tag 2") buildA printTest NSLog( "tag 2") work correctly, but buildA printTest get error Terminating app due to uncaught exception 'NSInvalidArgumentException', reason ' CCSprite printTest unrecognized selector sent to instance 0x18595f0' Obviously I'm referring to the wrong object. How I can get different method and property in contacted objects from contactlistener class?


Sliding movement on a grid I'm trying to implement quot sliding quot movement on a simple grid, where the movement vector is continuous (floating point direction) but the grid is discrete (boolean blocked or open on integer axes). The quot destination quot tile is found by adding the rounded movement vector to the current tile. That part is naive and works well enough. For example, here blue is the current (source) tile the yellow arrow is the movement vector green is the destination tile But this movement ends up being restrictive and I'd like to enable quot sliding quot to approximate player intent. My goal is that if the destination tile is blocked, the quot next best quot tile is used instead, provided it is available. I don't know how to calculate that. As you can see, the naive destination tile (where the yellow arrow lands) is blocked. As a result, I'd like to pick the green tile above as the destination tile. However, crossing a diagonal should be allowed either, so the following case should result in the movement being blocked Finally, I'd like this algorithm to be as permissive as possible, so even the smallest component of the movement vector could win if no better alternative is found. For example, the movement should carry upwards in that case This sounds like a fairly simple problem and there may be existing algorithms for it, but I don't know what it's called, so I'm having trouble finding resources on it.


Understanding unknown mesh data structure I have a large number of old mesh files in a custom, undocumented binary format. I have managed to parse almost everything but am left with one group of structures, described below, that I don't understand. I hope an experienced graphics programmer can explain what is happening. Here are the structures concerned These types are defined below. We're trying to understand what these three arrays are used to achieve. VertexRef vertexRefs Triangle triangles Unknown unknowns struct VertexRef Earlier in the file, there are several vertex buffers. The file can contain multiple meshes, either as components of a larger mesh, or as multiple LODs. This value group picks out one of these buffers. uint8 t group Index into the vertex buffer picked out by group . uint16 t vertexIndex struct TriangleVertex Index into the array vertexRefs uint16 t vertexRef Index into the array unknowns uint16 t unknownIndex struct Triangle TriangleVertex verts 3 struct Unknown Index into the array vertexRefs uint16 t vertexRef1 Index into the array triangles uint16 t triangleIndex1 Another index into the array vertexRefs uint16 t vertexRef2 triangleIndex2 can be 0xffff, while triangleIndex1 never is uint16 t triangleIndex2 The array of VertexRef is straightforward. It picks vertices, potentially from multiple meshes, to form a composite mesh. The array of Triangle is formed by vertices from the array of VertexRef. Each vertex is also associated with an Unknown. I am out of my depth in understanding what Unknown is doing. Member triangleIndex2 sometimes being 0xffff (or invalid, or nonexistent?) might indicate it is a leaf node of a tree? Perhaps the structure comprising the arrays vertexRefs, triangles and unknowns is some kind of collision detection tree? I'd be very grateful for any hints. Please ask questions if I've failed to be clear enough about something. Edit In answer to a request in comments, I am attaching a sample file and code to load it. The code should run on any likely system. The file is a mesh of a pair of boots. The file is hosted at uploadfiles.io https ufile.io w66mh


Isometric 3d collision detection I'm making an isometric map for a game, I can draw it, but I don't know how to implement a sort of 3d collision detection without Threejs or other 3d library. It is possible? Maybe make the block an Object can help? I have searched a lot on the web, but I found only libraries. Thank you! This is my JavaScript code var canvas document.getElementById('canvas'), ctx canvas.getContext('2d'), width canvas.width window.innerWidth, height canvas.height window.innerHeight, stop false var tw, th var player setup() draw() function setup() ctx.translate(width 2,50) tw 60 tile width th 30 tile height player new Player(2,3,2) function draw() ctx.clearRect( width 2, 50,width 1.5,height 50) for(var i 0 i lt 5 i ) for(var j 0 j lt 5 j ) drawBlock(i,j,1,tw,th) if(!stop) requestAnimationFrame(draw) function drawBlock(x,y,z,w,h) var top " eeeeee", right ' cccccc', left ' 999999' ctx.save() ctx.translate((x y) w 2,(x y) h 2) ctx.beginPath() ctx.moveTo(0, z h) ctx.lineTo(w 2,h 2 z h) ctx.lineTo(0,h z h) ctx.lineTo( w 2,h 2 z h) ctx.closePath() ctx.fillStyle "black" ctx.stroke() ctx.fillStyle top ctx.fill() ctx.beginPath() ctx.moveTo( w 2,h 2 z h) ctx.lineTo(0,h z h) ctx.lineTo(0,h) ctx.lineTo(0,h) ctx.lineTo( w 2,h 2) ctx.closePath() ctx.fillStyle "black" ctx.stroke() ctx.fillStyle left ctx.fill() ctx.beginPath() ctx.moveTo(w 2,h 2 z h) ctx.lineTo(0,h z h) ctx.lineTo(0,h) ctx.lineTo(0,h) ctx.lineTo(w 2,h 2) ctx.closePath() ctx.fillStyle "black" ctx.stroke() ctx.fillStyle right ctx.fill() ctx.restore() function drawTile(x,y,stroke,col) ctx.save() ctx.translate((x y) tw 2,(x y) th 2) ctx.beginPath() ctx.moveTo(0,0) ctx.lineTo(tw 2,th 2) ctx.lineTo(0,th) ctx.lineTo( tw 2,th 2) ctx.closePath() if(stroke) ctx.stroke() else ctx.fillStyle col ctx.fill() ctx.restore() function Player(x,y,z) this.x x this.y y this.z z this.w 10 width this.h 10 height canvas width 100 height 100 lt canvas id "canvas" gt lt canvas gt


How do I implement a AABB Sphere collision i have been trying to implement an aabb sphere collision. This is what I tried Override public boolean collides(Sphere other) Vector3f axis Vector3f.sub(Vector3f.sub(max, min, null), other.getCenter(), null) float dist axis.length() return dist lt (other.getRadius() other.getRadius())


Should your world map have it's own collision object? I am attempting to understand collision detection at the moment. I have seen many examples of a simple flat plane with boxes or cubes which move around on the plane and react when the touch each other (or stop at the plane when dropped). What I am not finding though are more advanced examples where instead of just a flat plane, your map is made up of hills, buildings, walls, etc. Since all of the examples I have found this far use simple primitive collision object types (boxes and spheres), I am curious what the best approach would be for creating a collision object for something like a game map (like dust2 in counter strike). After reading through the bullet documentation I found that you can create a collision object from a triangle mesh, which leads me to believe this might be the best approach. However if your map consists of complex geometry (say hundreds of thousands of verticies and faces), would this be too detailed to use as a collision mesh? Would it then be better to create a separate collision version of the map which is made of simple low poly shapes? My gut is saying "go with the separate low poly version", but if there is no reason for the extra work, it would make more sense to just use the high poly mesh.