collision-detection

iOS SpriteKit - collisions and contacts not working as expected [closed]

帅比萌擦擦* 提交于 2019-11-27 23:19:10
Sometimes in my SpriteKit programs, my collisions and contacts (using SKPhysicsBody) don't trigger or work as expected. I think I have set up everything I need, but I am still not getting the right interactions. How can I easily check what will collide with what and what bodies are set up to generate contacts? To help diagnose these types of problems, I have written a function that can be called from anywhere and which will analyse the current scene and produce a list of what nodes with collide with which others and which collisions my scene will be notified for. The function is stand-alone

Physics bodies other than my player won't call didBeginContact when colliding

你说的曾经没有我的故事 提交于 2019-11-27 23:18:53
In my game I have 4 bitmasks and everything is setup, yet didBeginContact only gets called when the first bitmask (playerCategory) collides with something. if 3 collides with 4, nothing happens, even though I have the contactTestBitMask set for them to collide. myscene.h self.physicsWorld.gravity = CGVectorMake(0.0, -2.45); self.physicsWorld.contactDelegate = self; self.player = [SKSpriteNode spriteNodeWithColor:[SKColor blueColor] size: CGSizeMake(10.0, 20.0)]; self.player.position = CGPointMake(20.0, self.frame.size.height); self.player.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize

How to recalculate axis-aligned bounding box after translate/rotate?

Deadly 提交于 2019-11-27 21:12:50
问题 When I first load my object I calculate the initial AABB with the max and min (x,y,z) points. But this is in object space and the object moves around the world and more importantly, rotates. How do I recalculate the new AABB every time the object is translated/rotated? This happens basically every frame, is it going to be a very intensive operation to recalculate the new AABB every frame? If so, what would be the alternative? I know AABBs will make my collision detection less accurate but it

Circle and Polygon Collision with Libgdx

荒凉一梦 提交于 2019-11-27 20:52:50
Is there a way in Libgdx to verify a collision between a Polygon and a Circle? I saw the Intersector class but only found collision test for Circle and Rectangle. What about any other Polygon? If I need to do it manually, what's the best way to do that using Libgdx? So, I managed to create a collision test method between a Circle and a Polygon. At least, it works for me. Here's the code: public boolean overlaps(Polygon polygon, Circle circle) { float []vertices=polygon.getTransformedVertices(); Vector2 center=new Vector2(circle.x, circle.y); float squareRadius=circle.radius*circle.radius; for

Detecting collision of rectangle with circle

ぐ巨炮叔叔 提交于 2019-11-27 18:53:27
Actually I am trying to detect thee collision of the Rectangle with the circle in the following piece of code:- function checkCollision() { //checking of the Collision if (ry + rh > cy - radius && rx + rw > cx - radius && rx + rw < cx + radius ) { dy = -dy; } } This is also the part of my code:- var rx = 50; //distance from the x-axis of the Rect. var ry = 50; //distance from the y-axis of the Rect. var rw = 80; //width of the Rect var rh = 30; //Height of the Rect. // Distance to moved of the Rect. var dx = 2; var dy = 2; // Center of the circle from the x-axis and y-axis. var cx = 105; var

OpenGL GL_SELECT or manual collision detection?

假如想象 提交于 2019-11-27 18:38:03
As seen in the image I draw set of contours (polygons) as GL_LINE_STRIP. Now I want to select curve(polygon) under the mouse to delete,move..etc in 3D . I am wondering which method to use: 1.use OpenGL picking and selection. ( glRenderMode(GL_SELECT) ) 2.use manual collision detection , by using a pick-ray and check whether the ray is inside each polygon. I strongly recommend against GL_SELECT . This method is very old and absent in new GL versions, and you're likely to get problems with modern graphics cards. Don't expect it to be supported by hardware - probably you'd encounter a software

How to fix circle and rectangle overlap in collision response?

心不动则不痛 提交于 2019-11-27 18:25:57
Since in the digital world a real collision almost never happens, we will always have a situation where the "colliding" circle overlaps the rectangle. How to put back the circle in the situation where it collides perfectly with the rectangle without overlap? Suppose that the rectangle is stopped (null velocity) and axis-aligned. I would solve this problem with a posteriori approach (in two dimensions). In short I have to solve this equation for t : Where: is a number that answers to the question: how many frames ago did the collision happen perfectly? is the radius of the circle. is the center

Test if two lines intersect - JavaScript function

旧街凉风 提交于 2019-11-27 17:37:56
I've tried searching for a javascript function that will detect if two lines intersect each other. The function will take the x,y values of both the start end points for each line (we'll call them line A and line B). Is to return true if they intersect, otherwise false. Example of the function. I'm happy if the answer uses a vector object instead. Function isIntersect (lineAp1x, lineAp1y, lineAp2x, lineAp2y, lineBp1x, lineBp1y, lineBp2x, lineBp2y) { // JavaScript line intersecting test here. } Some background info: this code is for a game I'm trying to make in html5 canvas, and is part of my

Collision detection between two rectangles in java

我只是一个虾纸丫 提交于 2019-11-27 15:19:37
I have two rectangles, the red rectangle (can move) and the blue rectangle. Both have: x, y, width, height. How can I say in a programming language such as Java when there is a collision between the blue and the red rectangle? if (RectA.X1 < RectB.X2 && RectA.X2 > RectB.X1 && RectA.Y1 < RectB.Y2 && RectA.Y2 > RectB.Y1) Say you have Rect A, and Rect B. Proof is by contradiction. Any one of four conditions guarantees that no overlap can exist: Cond1. If A's left edge is to the right of the B's right edge, - then A is Totally to right Of B Cond2. If A's right edge is to the left of the B's left

How can I perform Collision Detection on rotated rectangles? [closed]

孤人 提交于 2019-11-27 13:58:29
Okay, I'm trying to write a program that could tell me if any points in a 30x100 rectangle rotated to 140 degrees are inside another 30x100 rectangle rotated to 200 degrees. Honestly, I don't even know where to start. I thought about re-rotating them before doing normal calculations, but than they still wouldn't match up. How can I do this? 来源: https://stackoverflow.com/questions/641219/how-can-i-perform-collision-detection-on-rotated-rectangles