collision-detection

How do I implement collision detection?

﹥>﹥吖頭↗ 提交于 2019-12-02 13:24:27
from graphics import* import time import random def main(): numx=random.randint(10,700) wn=GraphWin("AK",700,700) wn.setBackground("white") msg=Text(Point(25,30),"Score") msg.setSize(12) msg.setTextColor('blue') msg.draw(wn) inch=Entry(Point(60,30),2) inch.setFill('white') inch.draw(wn) sqrg=Rectangle(Point(330,650),Point(430,665)) sqrg.setFill("red") sqrg.draw(wn) blx=Circle(Point(numx,80),20) blx.setFill("blue") blx.draw(wn) xval=10 yval=0 wn.getMouse() for i in range(150): sqrg.move(xval,yval) symbl=wn.checkKey() if symbl=="Right": xval=10 yval=0 if symbl=="Left": xval=-10 yval=0 time.sleep

jQuery spawning div and collision detection

余生长醉 提交于 2019-12-02 13:07:20
So im almost at the end of my school homework project im just missing two major things i can't seem to figure out: 1.How to spawn the pipe obstacles with a random position for the gap so the bird can fly through (tought of using a function which changes the css 'right' attr of the pipe div for the gap position), and removing the pipe when it goes off screen bottom . (Its a inverted flappy bird game like btw..) 2.Second i need a help with the collision detection function so i know when game is over (this is less important tough cause i think i can figure it out after ill solve the first problem

cocos2d v3 collision detection

纵然是瞬间 提交于 2019-12-02 10:43:11
问题 I'm trying to inspect collision collision of two bodies, but collision detection callbacks are not being fired. Here is my code: 1) My CCScene implements CCPhysicsCollisionDelegate protocol 2) I set collision delegate for physics _physics = [CCPhysicsNode node]; _physics.gravity = PHYSICS_GRAVITY; _physics.debugDraw = YES; _physics.collisionDelegate = self; [self addChild:_physics]; 3) For each of two body I set a collision type body1.collisionType = @"body1"; body2.collisionType = @"body2";

Box collision detection and bouncing

时间秒杀一切 提交于 2019-12-02 10:03:10
I'm making pong, and am finding it really difficult to write an algorithm that bounces the ball off the four walls properly (I will deal with scoring later on, because only part of the West+East sides will be goals). So at the moment I want the ball to bounce around the box. Detecting whether the ball has hit a wall is easy, but I'm having trouble calculating the new angle. This is what I've come up with so far: if(dstY == 0) { // North wall if(angle < 90) { newAngle = angle + 90; } else { newAngle = angle - 90; } } else if(dstX == maxWidth) { // East wall if(angle < 90) { newAngle = angle +

Collision Detection in Flash Functionalities? (hitTestObject)

折月煮酒 提交于 2019-12-02 09:58:22
Hello, so I've been recently using hitTestObject to detect collisions in an android app I'm making. After testing for a bit, I realized that the game was detecting "fake" collisions. What I mean by this is that it was detecting a collisions not when the pixels of an object(s) are touching, but (after doing a bit of research) I found out that the boxes of the objects where colliding. So I had the game stop with a collision, and this is how it looks like: I tried outlining the two object's boxes, for clarity. As you can see their boxes are touching. Is there any way to have it detect when pixels

how to detect when a ImageView is in collision with another ImageView?

爷,独闯天下 提交于 2019-12-02 09:23:49
Im developing a test game with some imageviews on the screen. with the finger, i am moving another imageview. I want to detect when the imageview moved by the finger has touched another imageview. ¿Wich is the best way to achieve it? I can't find info about it on google... Thanks I'll answer the general question - find out when two views overlap : private boolean viewsOverlap(View v1, View v2) { int[] v1_coords = new int[2]; v1.getLocationOnScreen(v1_coords); int v1_w = v1.getWidth(); int v1_h = v1.getHeight(); Rect v1_rect = new Rect(v1_coords[0], v1_coords[1], v1_coords[0] + v1_w, v1_coords

Collision detection 2D between rectangles

戏子无情 提交于 2019-12-02 09:17:50
问题 I am writting a collision detection engine for my game and I have some problems. Indeed, since I have several fixed rectangle and one moving (the player), I need to know which side of the fixed one was collided at first by the player, to replace him correctly. The fixed rectangle are NOT in a grid so they can be placed anywhere on the map and they can have diffents size. They are not rotated. The player class stores it's direction vector. Any idea? KiTe 回答1: In a nutshell: You'll compare the

IOS SpriteKit Colision Detection: Resetting Position of an Object

核能气质少年 提交于 2019-12-02 08:56:14
问题 I'm working on Collision Detection where the hope is when Object1 moves down the screen and eventually hits Object2 it triggers the didBeginContact method and in turn, the resetPosition on Object1 which will bring Object1 back to the top of the screen. I've used NSLogs to test to make sure if the program reaches the didBeginContact method, and it does. On top of that, the program also works through the called upon method (resetPosition) as well. The only problem is, it does not change the

physics engine - phase order and other general information

六眼飞鱼酱① 提交于 2019-12-02 07:30:23
问题 I want to build my own 2D mini-physics engine, that will include(for now) rigid bodys, and constraints (joints, contacts, springs...). And I've tried to figure out what is the right order of the phases, when I start a timestep, when the the general phases are: Broadphase, Narrow phase(Collision Detection, and Contact generation), Resolution (Constraints Solver), and the Integration - hope you can tell me the right order. I allso have general questions about each phase: Narrow Phase - When I

How to determine which side of a rectangle collides with a circle

≯℡__Kan透↙ 提交于 2019-12-02 07:17:21
问题 Before you point out that there are other answers to this question, i have looked at if not all, most of the other answers to this question or a similar question and i haven't found the solution i require. Basically all i want to be able to do is when the circle/ball collides with a rectangle, i want to determine which side of the rectangle this collision has occured at. I want to find this out so that i can enforce a bit more realistic physics, e.g. if the ball hits the top of the rectangle,