collision-detection

Simple Javascript collision detection?

ⅰ亾dé卋堺 提交于 2021-01-27 06:00:29
问题 I'm trying to make a simple game using jquery,javascript,html and css. I keep getting stuck on collision detection. code: var map = [ [0,1,0,0,0,1,0,0,], [0,1,0,0,0,1,0,0,], [0,1,0,0,0,1,0,0,], [0,1,1,1,0,1,0,0,], [0,0,0,0,0,0,0,2,] ]; function DrawMap() { for(var i=0; i < map.length; i++){ for(var j=0; j < map[i].length; j++){ if(parseInt(map[i][j]) == 0){ $("#container").append("<div class='air'></div>"); } if(parseInt(map[i][j]) == 1){ $("#container").append("<div class='block'></div>"); }

find intersection point of two vectors independent from direction

有些话、适合烂在心里 提交于 2021-01-21 11:46:12
问题 I have two vectors and i want to know where these vectors will intersect independent from direction or length. So lets just say i would draw an infinite line in either direction and i want to know where those two lines will intersect and get the coordinates. See image below for clarification: So i want to know the coordinates of the pink X. But i can only find formulas for calculating the intersection point of two lines with an stard and end point which i dont have :( So i am looking for some

Trouble with separating axis theorem C++

人盡茶涼 提交于 2020-12-26 12:45:58
问题 I am trying to perform separating axis theorem on two triangles to test for collisions between them however it is not working. My relevant code is: glm::vec3 CalcSurfaceNormal(glm::vec3 tri1, glm::vec3 tri2, glm::vec3 tri3) { //Get surface normal of a triangle glm::vec3 u = tri2 - tri1; glm::vec3 v = tri3 - tri1; glm::vec3 nrmcross = glm::cross(u, v); nrmcross = glm::normalize(nrmcross); return nrmcross; } bool SATTriangleCheck(glm::vec3 axis, glm::vec3 tri1vert1, glm::vec3 tri1vert2, glm:

Pygame collision with masks is not working

做~自己de王妃 提交于 2020-12-26 04:39:44
问题 I have made a putt-putt game and now I want to add a slanted wall type. Because of this, I need to use masks for the collision (until now I have just used rects). I have spent hours learning about masks and trying to figure out why my code won't work. There are no errors, the collision just isn't detected. I have simplified my code down to something much smaller just as a way for me to test it efficiently. From everything I've seen this seems like it should work, but it doesnt. Here it is:

Pygame collision with masks is not working

杀马特。学长 韩版系。学妹 提交于 2020-12-26 04:39:05
问题 I have made a putt-putt game and now I want to add a slanted wall type. Because of this, I need to use masks for the collision (until now I have just used rects). I have spent hours learning about masks and trying to figure out why my code won't work. There are no errors, the collision just isn't detected. I have simplified my code down to something much smaller just as a way for me to test it efficiently. From everything I've seen this seems like it should work, but it doesnt. Here it is:

How to detect when a rectangular object, image or sprite is clicked

妖精的绣舞 提交于 2020-12-21 04:11:28
问题 I'm trying to tell when a sprite, which must be part of a particular group ( pygame.sprite.Group() ), is clicked on. Currently I've tried creating a sprite which is just the mouses position and totally invisible, adding it to its own group, and using this code: clickedList = pygame.sprite.spritecollide(guess1, mice, False) where guess1 is the sprite getting clicked on and mice is the group containing the sprite that has the position of the mouse. When I try this, I am told that "Group has no

How to detect when a rectangular object, image or sprite is clicked

感情迁移 提交于 2020-12-21 04:10:07
问题 I'm trying to tell when a sprite, which must be part of a particular group ( pygame.sprite.Group() ), is clicked on. Currently I've tried creating a sprite which is just the mouses position and totally invisible, adding it to its own group, and using this code: clickedList = pygame.sprite.spritecollide(guess1, mice, False) where guess1 is the sprite getting clicked on and mice is the group containing the sprite that has the position of the mouse. When I try this, I am told that "Group has no

SpriteCollide Only Running Once Per Collision

时光怂恿深爱的人放手 提交于 2020-12-14 06:40:13
问题 I'm checking missileGroup to see if any instances of missile collided with any instances enemy in enemyGroup . When run, it prints "Hit" for the first loop, but it ignores the second for loop. Why is that? #### Imagine this is in a game loop #### for missile in missileGroup: if pygame.sprite.spritecollide(missile, enemyGroup, False) : print("Hit") for enemy in enemyGroup: if pygame.sprite.spritecollide(enemy, missileGroup, False) == True: print("HI") 回答1: pygame.sprite.spritecollide() doesn't

SpriteCollide Only Running Once Per Collision

隐身守侯 提交于 2020-12-14 06:39:42
问题 I'm checking missileGroup to see if any instances of missile collided with any instances enemy in enemyGroup . When run, it prints "Hit" for the first loop, but it ignores the second for loop. Why is that? #### Imagine this is in a game loop #### for missile in missileGroup: if pygame.sprite.spritecollide(missile, enemyGroup, False) : print("Hit") for enemy in enemyGroup: if pygame.sprite.spritecollide(enemy, missileGroup, False) == True: print("HI") 回答1: pygame.sprite.spritecollide() doesn't

the car moves and changes direction when it hits the window edge [closed]

余生长醉 提交于 2020-12-13 03:18:41
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 12 days ago . Improve this question The car is moving straight. When it hits the window edge it moves backwards then changes direction at an angle of 45 degrees clockwise and keeps moving straight. if it hit the edge of the window again, it would do the same I've made the code below. I was only