collision-detection

AS3: Random Point on Irregular Shape

不羁的心 提交于 2019-12-11 06:49:40
问题 I have a MovieClip holding an irregular shape such as this one: I need to generate a random point on this shape. I can use brute force by generating points within the bounding box and then hitTesting to see if they reside on the irregular shape. However, I'm sure there's a more efficient way to tackle this problem. What is the most efficient way to generate a random point on an irregular shape? 回答1: You mentioned hitTest, but I assume you meant hitTestPoint(). If so, a function go get the

Jquery event for breaking draggable containment

五迷三道 提交于 2019-12-11 06:24:15
问题 I want to add a callback for when a draggable item breaks it's containment. I have this function: function makeDraggable(){ $( ".draggable" ).draggable({ containment: "parent" , grid: [ 25, 25 ] }); } Is there a simple way to achieve this, without using collision detection? If not, how would I go about doing the collision detection? 回答1: You can check the 4 corners of the element when it is dropped against the 4 corners of another element to see if any of the corners are inside that element

Collision accuracy

邮差的信 提交于 2019-12-11 06:16:40
问题 Not quite sure how to word this but I've been using if (CGRectIntersectsRect(ball.frame, bottom.frame)) { [self finish ]; } for my collision detection and it run the code perfectly but the ball sometimes collides with the bottom and runs the code but you can clearly see there is a gap in between the objects. i have created the images my self and they have no background around them. i was wondering if theres any other way of coding it or making it so the it doesn't run the code until the

cocos2d Children sprite collision detection with parent sprite

元气小坏坏 提交于 2019-12-11 04:49:13
问题 Hi stackoverflow community! How do you detect a children sprite collision with a parent sprite in cocos2d? Currently I have my codes like this: CGSize screenSize = [[CCDirector sharedDirector]winSize]; parentJumper = [CCSprite spriteWithFile:@"inviBtn.png"]; jumper = [CCSprite spriteWithFile:@"jumperRight.png"]; plat = [[Platform alloc]init]; plat = [Platform spriteWithFile:@"platformBlack.png"]; plat.position = ccp(160,100); [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0/60)];

Fast moving object passing through other objects

爱⌒轻易说出口 提交于 2019-12-11 04:33:58
问题 I am pretty new to Unity and am making a small example. Actually I have a cube which moves with my arrow keys. Now I have walls on the road, and I want my object to hit the wall but it pass through the wall. I also have used this code, but no result: http://www.unifycommunity.com/wiki/index.php?title=DontGoThroughThings 回答1: The general idea is to track the last position of your object(s), and then when they move, cast a ray from the current position to the last position. Check the ray for

BoundingBoxes for Collision Detection overlapping and causing issues

喜你入骨 提交于 2019-12-11 03:50:09
问题 The following code is my attempt at stopping the PC (player character) from walking through an NPC. The "if" statement checks if the two rectangles (BoundingBox) intersect. collisionBox defines the area of the overlapping BoundingBoxes moveDir defines the Vector change that the PC will be undergoing after the if statement (e.g: if moveDir=(2,0) the PC will move to the right two pixels) currentSpeed defines the value being assigned to moveDir.X or moveDir.Y depending on keyboard input (up,

how does collide.rect work in pygame

孤街浪徒 提交于 2019-12-11 03:16:40
问题 I'm having some trouble understanding how colliderect works with sprites. I have a good idea about it, but whenever I try to implement it into my game, I just get the error message "attributeError:'pygame.surface' object has no attribute 'rect'" ufo_lvl_1 = pygame.image.load("ufo1.png") bullet = pygame.image.load("bullet.png") class Bullet(pygame.sprite.Sprite): def __init__(self): # Call the parent class (Sprite) constructor pygame.sprite.Sprite.__init__(self) self.image = bullet self.damage

Collision Detection between a Oval and Arc

谁说我不能喝 提交于 2019-12-11 01:44:24
问题 I am writing a simple game, or so it seemed. I created a class that draws a Arc2D (half a circle shape), that same class will repaint the arch as the mouse move. Then I created a new class that draws ovals. This class has some simple mathematics to move the ovals on the screen. The movement of the ovals are not very important. So now that this is done I want to detect if the Oval collides with the arc(half a circle, Only the arc line ) at any point. What I have attempted is making the oval a

Line collision in pygame

☆樱花仙子☆ 提交于 2019-12-11 01:27:03
问题 So I am currently working on a 2D platformer game and i have realized a big issue with my collision programming. You see, to find out collisions with the player I just moved the player rect around, then when colliding i pushed the player away by looking at the x and y acceleration on him. The problem is though, when using this method, the player speed can make the player skip over targets he is supposed to collide with because the rect he is supposed to collide with is too small. For example

AABB in a game with moveable and rotateable characters/objects/etc

為{幸葍}努か 提交于 2019-12-10 21:46:12
问题 In those day I'm creating my very first 3d game and I've ran into couple of problems. I read about AABB intersectioning and the idea of building trees from it, but the one thing that I couldn't understand is, if my "character" rotates during the game, the concept of the Axis-aligned isn't preserved! I've checked a couple of libraries (like oz-collide, OPCODE, and more), and I've seen that the implementations were made for static objects, because it uses the boxes without an origin (for non