Search Results

Search found 1014 results on 41 pages for 'collision'.

Page 12/41 | < Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >

  • Collision Detection (Ground & Slopes) in 2D Platform Game using Pygame Rects

    - by RedCap
    Hi, First off, I am not after any instructions on logic for collision detection; I get it. What I am trying to work out is the least complicated way to do this with Pygame using Sprites & Rects. I want to be able to check collisions for the Player against ground, walls & slopes. In theory it is quite straight forward, but I'm having difficulty because it seems like you cannot do this with one Rect. One Rect is simple enough to get you collisions in the X plane against walls. The same Rect could be used also be used in the Y plane against solids, but not with slopes - since with the collision routines in Pygame it checks the whole Rect (or mask), rather than perhaps just the bottom middle of the Rect. It seems in addition you need to have a number of "sprites" to check collisions with, that are 1x1 pixel in various places around the Player. What's the easiest way to do this, without having a bunch of 3, 4, or more separate "collision pixels" to check against slopes? Geoff

    Read the article

  • 2d ball collision code problem XNA, over accelerated balls and stick together sometimes. help please? [closed]

    - by Sivan
    public static void Collision(Ball ball1, Ball ball2) { Vector3 x = new Vector3((ball1.BallPosition.X - ball2.BallPosition.X), (ball1.BallPosition.Y - ball2.BallPosition.Y), 0); x.Normalize(); Vector3 v1 = new Vector3(ball1.Speed, 0); float x1 = Vector3.Dot(x, v1); Vector3 v1x = x * x1; Vector3 v1y = v1 - v1x; x = -x; Vector3 v2 = new Vector3(ball2.Speed, 0); float x2 = Vector3.Dot(x, v2); Vector3 v2x = x * x2; Vector3 v2y = v2 - v2x; float m1 = 12, m2 = 4; float combinedMass = m1 + m2; Vector3 newVelA = (v1x * ((m1 - m2) / combinedMass)) + (v2x * ((2f * m2) / combinedMass)) + v1y; Vector3 newVelB = (v1x * ((2f * m1) / combinedMass)) + (v2x * ((m2 - m1) / combinedMass)) + v2y; ball1.Speed = new Vector2(newVelA.X, newVelA.Y); ball2.Speed = new Vector2(newVelB.X,newVelB.Y ); }

    Read the article

  • How can i get almost pixel perfect collision detection in a multiplayer game?

    - by Freddy
    I'm currently working on a multiplayer game for iPhone. The problem i have, as with all multiplayer games, is that the other user will always see everything at a non-constant delay. The game I'm making need to have a almost pixel perfect collision detection, but 1 or 2 pixels off is not that big of a deal. How can I possibly get this working? I guess I could just set local player to also be at X ms delay. However this will probably just be worse and feel sloppy when the user input. I know this problem is probably something network programmers deal with everyday and I would be glad if someone could give me a possible solution for this.

    Read the article

  • Using PhysX, how can I predict where I will need to generate procedural terrain collision shapes?

    - by Sion Sheevok
    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?

    Read the article

  • Where should I place my reaction code in Per-Pixel Collision Detection?

    - by CJ Cohorst
    I have this collision detection code: public bool PerPixelCollision(Player player, Game1 dog) { Matrix atob = player.Transform * Matrix.Invert(dog.Transform); Vector2 stepX = Vector2.TransformNormal(Vector2.UnitX, atob); Vector2 stepY = Vector2.TransformNormal(Vector2.UnitY, atob); Vector2 iBPos = Vector2.Transform(Vector2.Zero, atob); for(int deltax = 0; deltax < player.playerTexture.Width; deltax++) { Vector2 bpos = iBPos; for (int deltay = 0; deltay < player.playerTexture.Height; deltay++) { int bx = (int)bpos.X; int by = (int)bpos.Y; if (bx >= 0 && bx < dog.dogTexture.Width && by >= 0 && by < dog.dogTexture.Height) { if (player.TextureData[deltax + deltay * player.playerTexture.Width].A > 150 && dog.TextureData[bx + by * dog.Texture.Width].A > 150) { return true; } } bpos += stepY; } iBPos += stepX; } return false; } What I want to know is where to put in the code where something happens. For example, I want to put in player.playerPosition.X -= 200 just as a test, but I don't know where to put it. I tried putting it under the return true and above it, but under it, it said unreachable code, and above it nothing happened. I also tried putting it by bpos += stepY; but that didn't work either. Where do I put the code?

    Read the article

  • How to choose cell to put entity in in an uniform grid used for broad phase collision detection?

    - by nathan
    I'm trying to implement the broad phase of my collision detection algorithm. My game is an arcade game with lot of moving entities in an open space with relatively equivalent sizes. Regarding the above specifications, i decided to use an uniform grid for space partitioning. The problem i have right know is how to efficiently choose in which cells an entity should be added. ATM i'm doing something like this: for (int x = 0; x < gridSize; x++) { for (int y = 0; y < gridSize; y++) { GridCell cell = grid[x][y]; cell.clear(); //remove the previously added entities for (int i = 0; i < entities.size(); i++) { Entity e = entities.get(i); if (cell.isEntityOverlap(e)) { cell.add(e); } } } } The isEntityOverlap is a simple method i added my GridCell class. public boolean isEntityOverlap(Shape s) { return cellArea.intersects(s); } Where cellArea is a Rectangle. cellArea = new Rectangle(x, y, CollisionGrid.CELL_SIZE, CollisionGrid.CELL_SIZE); It works but it's damn slow. What would be a fast way to know all the cells an entity overlaps? Note: by "it works" i mean, the entities are contained in the good cells over the time after movements etc.

    Read the article

  • How to fetch only the sprites in the player's range of motion for collision testing? (2D, axis aligned sprites)

    - by Twodordan
    I am working on a 2D sprite game for educational purposes. (In case you want to know, it uses WebGl and Javascript) I've implemented movement using the Euler method (and delta time) to keep things simple. Now I'm trying to tackle collisions. The way I wrote things, my game only has rectangular sprites (axis aligned, never rotated) of various/variable sizes. So I need to figure out what I hit and which side of the target sprite I hit (and I'm probably going to use these intersection tests). The old fashioned method seems to be to use tile based grids, to target only a few tiles at a time, but that sounds silly and impractical for my game. (Splitting the whole level into blocks, having each sprite's bounding box fit multiple blocks I might abide. But if the sprites change size and move around, you have to keep changing which tiles they belong to, every frame, it doesn't sound right.) In Flash you can test collision under one point, but it's not efficient to iterate through all the elements on stage each frame. (hence why people use the tile method). Bottom line is, I'm trying to figure out how to test only the elements within the player's range of motion. (I know how to get the range of motion, I have a good idea of how to write a collisionCheck(playerSprite, targetSprite) function. But how do I know which sprites are currently in the player's vicinity to fetch only them?) Please discuss. Cheers!

    Read the article

  • Huge dataset point in polygon in .net (collision detection)

    - by Rickard Liljeberg
    I have a pretty big mesh with polygons, usually triangles but sometimes rectangles. Each point in my mesh has a value (value has nothing to do with coordinates). Now I am creating a second mesh in the same coordinate-space as the old mesh. I now want to interpolate out values for all points (vertices) in the new mesh using the values from the old mesh. Now I could loop each polygon in the new mesh and detect which old vertices are in each polygon by making 2d collision detection (altho even this I don't get to function properly so if anyone has simple and fast code for 2d collision detection (triangle is enough) I would gladly see it). However to my main point again. looping each old vertice for each new polygon seems less than efficient. is there a better way?

    Read the article

  • Collision detection by sliding against a plane in XNA

    - by Bevin
    Hello, I am attempting to engineer a collision detection algorithm for a custom Minecraft client I'm making. Basically, the entire world is made up of cubes, and the player (or camera) needs to be able to stand on and move against these cubes. The result I want is illustrated in this image: The green line is the player's movement vector. When the player is brushing up against a plane of one of the cubes, I want the vector to change to one that is perpendicular with the plane. The vector should, however, keep all of it's velocity in the plane's direction, yet lose all velocity towards the plane. I hope I've made my question clear. What is the best and most efficient way to implement a collision detection system like this? Also, will a system like this allow for a simple gravity component?

    Read the article

  • Collision Detection probelm (intersection with plane)

    - by Demi
    I'm doing a scene using openGL (a house). I want to do some collision detection, mainly with the walls in the house. I have tried the following code: // a plane is represented with a normal and a position in space Vector planeNor(0,0,1); Vector position(0,0,-10); Plane p(planeNor,position); Vector vel(0,0,-1); double lamda; // this is the intersection point Vector pNormal; // the normal of the intersection // this method is from Nehe's Lesson 30 coll= p.TestIntersionPlane(vel,Z,lamda,pNormal); glPushMatrix(); glBegin(GL_QUADS); if(coll) glColor3f(1,0,0); else glColor3f(1,1,1); glVertex3d(0,0,-10); glVertex3d(3,0,-10); glVertex3d(3,3,-10); glVertex3d(0,3,-10); glEnd(); glPopMatrix(); Nehe's method: #define EPSILON 1.0e-8 #define ZERO EPSILON bool Plane::TestIntersionPlane(const Vector3 & position,const Vector3 & direction, double& lamda, Vector3 & pNormal) { double DotProduct=direction.scalarProduct(normal); // Dot Product Between Plane Normal And Ray Direction double l2; // Determine If Ray Parallel To Plane if ((DotProduct<ZERO)&&(DotProduct>-ZERO)) return false; l2=(normal.scalarProduct(position))/DotProduct; // Find Distance To Collision Point if (l2<-ZERO) // Test If Collision Behind Start return false; pNormal= normal; lamda=l2; return true; } Z is initially (0,0,0) and every time I move the camera towards the plane, I reduce its z component by 0.1 (i.e. Z.z-=0.1 ). I know that the problem is with the vel vector, but I can't figure out what the right value should be. Can anyone please help me?

    Read the article

  • Draw Rectangle To All Dimensions of Image

    - by opiop65
    I have some rudimentary collision code: public class Collision { static boolean isColliding = false; static Rectangle player; static Rectangle female; public static void collision(){ Rectangle player = Game.Playerbounds(); Rectangle female = Game.Femalebounds(); if(player.intersects(female)){ isColliding = true; }else{ isColliding = false; } } } And this is the rectangle code: public static Rectangle Playerbounds() { return(new Rectangle(posX, posY, 25, 25)); } public static Rectangle Femalebounds() { return(new Rectangle(femaleX, femaleY, 25, 25)); } My InputHandling class: public static void movePlayer(GameContainer gc, int delta){ Input input = gc.getInput(); if(input.isKeyDown(input.KEY_W)){ Game.posY -= walkSpeed * delta; walkUp = true; if(Collision.isColliding == true){ Game.posY += walkSpeed * delta; } } if(input.isKeyDown(input.KEY_S)){ Game.posY += walkSpeed * delta; walkDown = true; if(Collision.isColliding == true){ Game.posY -= walkSpeed * delta; } } if(input.isKeyDown(input.KEY_D)){ Game.posX += walkSpeed * delta; walkRight = true; if(Collision.isColliding == true){ Game.posX -= walkSpeed * delta; } } if(input.isKeyDown(input.KEY_A)){ Game.posX -= walkSpeed * delta; walkLeft = true; if(Collision.isColliding == true){ Game.posX += walkSpeed * delta; } } } The code works partially. Only the right and top side of the images collide. How do I correct the rectangle so it will draw on all sides? Thanks for any suggestions!

    Read the article

  • What is the best way to implement collision detection using Bullet physics engine and a track generated from a curve?

    - by tigrou
    I am developing a small racing game were the track is generated from a curve. As said above, the track is generated, but not infinite. The track of one level could fit with no problem in memory and will contain a reasonably small amount of triangles. For collisions, I would like to use Bullet physics engine and know what is the best way to handle collisions with the track efficiently. NOTE : The track will be stored as a static rigid body (mass = 0). The player will be represented by a sphere shape for collisions. Here is some possibilities i have in mind : Create one rigid body, then, put all triangles of the track (except non collidable stuff) into it. Result : 1 body with many triangles (eg : 30000 triangles) Split the track into several sections (eg: 10 sections). Then, for each section, create a rigid body and put corresponding triangles in it. Result : small amount of bodies with relatively small amount of triangles (eg : 1500 triangles per section). Split the track into many sub-sections (eg : 1200 sections). Here one subsection = very small step when generating the curve. Again for each sub-section, create a body and put triangles in it. Result : many bodies with very small amount of triangles (eg : 20 triangles). Advantage : it could be possible to "extra data" to each of the subsection, that could be used when handling collisions. Same as 2, but only put sections N and N+1 in physics engine (where N = current section where the player is). When player reach section N+1, unload section N and load section N+2 and so on... Issue : harder to implement, problems if the player suddenly "jump" from one section to another (eg : player fly away from section N, and fall on section N + 4 that was underneath : no collision handled, player will fall into void ) Same as 4, but with many sub-sections. Issues : since subsections are very small there will be constantly new bodies added and removed to physics engine at runtime. Possibilities for player to accidently skip some sections and fall into the void are higher than 4.

    Read the article

  • Tile Collision & Sliding against tiles

    - by Devin Rawlek
    I have a tile based map with a top down camera. My sprite stops moving when he collides with a wall in any of the four directions however I am trying to get the sprite to slide along the wall if more than one directional key is pressed after being stopped. Tiles are set to 32 x 32. Here is my code; // Gets Tile Player Is Standing On var splatterTileX = (int)player.Position.X / Engine.TileWidth; var splatterTileY = (int)player.Position.Y / Engine.TileHeight; // Foreach Layer In World Splatter Map Layers foreach (var layer in WorldSplatterTileMapLayers) { // If Sprite Is Not On Any Edges if (splatterTileX < layer.Width - 1 && splatterTileX > 0 && splatterTileY < layer.Height - 1 && splatterTileY > 0) { tileN = layer.GetTile(splatterTileX, splatterTileY - 1); // North tileNE = layer.GetTile(splatterTileX + 1, splatterTileY - 1); // North-East tileE = layer.GetTile(splatterTileX + 1, splatterTileY); // East tileSE = layer.GetTile(splatterTileX + 1, splatterTileY + 1); // South-East tileS = layer.GetTile(splatterTileX, splatterTileY + 1); // South tileSW = layer.GetTile(splatterTileX - 1, splatterTileY + 1); // South-West tileW = layer.GetTile(splatterTileX - 1, splatterTileY); // West tileNW = layer.GetTile(splatterTileX - 1, splatterTileY - 1); // North-West } // If Sprite Is Not On Any X Edges And Is On -Y Edge if (splatterTileX < layer.Width - 1 && splatterTileX > 0 && splatterTileY == 0) { tileE = layer.GetTile(splatterTileX + 1, splatterTileY); // East tileSE = layer.GetTile(splatterTileX + 1, splatterTileY + 1); // South-East tileS = layer.GetTile(splatterTileX, splatterTileY + 1); // South tileSW = layer.GetTile(splatterTileX - 1, splatterTileY + 1); // South-West tileW = layer.GetTile(splatterTileX - 1, splatterTileY); // West } // If Sprite Is On +X And -Y Edges if (splatterTileX == layer.Width - 1 && splatterTileY == 0) { tileS = layer.GetTile(splatterTileX, splatterTileY + 1); // South tileSW = layer.GetTile(splatterTileX - 1, splatterTileY + 1); // South-West tileW = layer.GetTile(splatterTileX - 1, splatterTileY); // West } // If Sprite Is On +X Edge And Y Is Not On Any Edge if (splatterTileX == layer.Width - 1 && splatterTileY < layer.Height - 1 && splatterTileY > 0) { tileS = layer.GetTile(splatterTileX, splatterTileY + 1); // South tileSW = layer.GetTile(splatterTileX - 1, splatterTileY + 1); // South-West tileW = layer.GetTile(splatterTileX - 1, splatterTileY); // West tileNW = layer.GetTile(splatterTileX - 1, splatterTileY - 1); // North-West tileN = layer.GetTile(splatterTileX, splatterTileY - 1); // North } // If Sprite Is On +X And +Y Edges if (splatterTileX == layer.Width - 1 && splatterTileY == layer.Height - 1) { tileW = layer.GetTile(splatterTileX - 1, splatterTileY); // West tileNW = layer.GetTile(splatterTileX - 1, splatterTileY - 1); // North-West tileN = layer.GetTile(splatterTileX, splatterTileY - 1); // North } // If Sprite Is Not On Any X Edges And Is On +Y Edge if (splatterTileX < (layer.Width - 1) && splatterTileX > 0 && splatterTileY == layer.Height - 1) { tileW = layer.GetTile(splatterTileX - 1, splatterTileY); // West tileNW = layer.GetTile(splatterTileX - 1, splatterTileY - 1); // North-West tileN = layer.GetTile(splatterTileX, splatterTileY - 1); // North tileNE = layer.GetTile(splatterTileX + 1, splatterTileY - 1); // North-East tileE = layer.GetTile(splatterTileX + 1, splatterTileY); // East } // If Sprite Is On -X And +Y Edges if (splatterTileX == 0 && splatterTileY == layer.Height - 1) { tileN = layer.GetTile(splatterTileX, splatterTileY - 1); // North tileNE = layer.GetTile(splatterTileX + 1, splatterTileY - 1); // North-East tileE = layer.GetTile(splatterTileX + 1, splatterTileY); // East } // If Sprite Is On -X Edge And Y Is Not On Any Edges if (splatterTileX == 0 && splatterTileY < (layer.Height - 1) && splatterTileY > 0) { tileN = layer.GetTile(splatterTileX, splatterTileY - 1); // North tileNE = layer.GetTile(splatterTileX + 1, splatterTileY - 1); // North-East tileE = layer.GetTile(splatterTileX + 1, splatterTileY); // East tileSE = layer.GetTile(splatterTileX + 1, splatterTileY + 1); // South-East tileS = layer.GetTile(splatterTileX, splatterTileY + 1); // South } // If Sprite Is In The Top Left Corner if (splatterTileX == 0 && splatterTileY == 0) { tileE = layer.GetTile(splatterTileX + 1, splatterTileY); // East tileSE = layer.GetTile(splatterTileX + 1, splatterTileY + 1); // South-East tileS = layer.GetTile(splatterTileX, splatterTileY + 1); // South } // Creates A New Rectangle For TileN tileN.TileRectangle = new Rectangle(splatterTileX * Engine.TileWidth, (splatterTileY - 1) * Engine.TileHeight, Engine.TileWidth, Engine.TileHeight); // Tile Collision Detection Between Player Rectangle And N Tile var tileNCollision = player.Rectangle.Intersects(tileN.TileRectangle); // Creates A New Rectangle For TileNE tileNE.TileRectangle = new Rectangle((splatterTileX + 1) * Engine.TileWidth, (splatterTileY - 1) * Engine.TileHeight, Engine.TileWidth, Engine.TileHeight); // Tile Collision Detection Between Player Rectangle And NE Tile var tileNECollision = player.Rectangle.Intersects(tileNE.TileRectangle); // Creates A New Rectangle For TileE tileE.TileRectangle = new Rectangle((splatterTileX + 1) * Engine.TileWidth, splatterTileY * Engine.TileHeight, Engine.TileWidth, Engine.TileHeight); // Tile Collision Detection Between Player Rectangle And E Tile var tileECollision = player.Rectangle.Intersects(tileE.TileRectangle); // Creates A New Rectangle For TileSE tileSE.TileRectangle = new Rectangle((splatterTileX + 1) * Engine.TileWidth, (splatterTileY + 1) * Engine.TileHeight, Engine.TileWidth, Engine.TileHeight); // Tile Collision Detection Between Player Rectangle And SE Tile var tileSECollision = player.Rectangle.Intersects(tileSE.TileRectangle); // Creates A New Rectangle For TileS tileS.TileRectangle = new Rectangle(splatterTileX * Engine.TileWidth, (splatterTileY + 1) * Engine.TileHeight, Engine.TileWidth, Engine.TileHeight); // Tile Collision Detection Between Player Rectangle And S Tile var tileSCollision = player.Rectangle.Intersects(tileS.TileRectangle); // Creates A New Rectangle For TileSW tileSW.TileRectangle = new Rectangle((splatterTileX - 1) * Engine.TileWidth, (splatterTileY + 1) * Engine.TileHeight, Engine.TileWidth, Engine.TileHeight); // Tile Collision Detection Between Player Rectangle And SW Tile var tileSWCollision = player.Rectangle.Intersects(tileSW.TileRectangle); // Creates A New Rectangle For TileW tileW.TileRectangle = new Rectangle((splatterTileX - 1) * Engine.TileWidth, splatterTileY * Engine.TileHeight, Engine.TileWidth, Engine.TileHeight); // Tile Collision Detection Between Player Rectangle And Current Tile var tileWCollision = player.Rectangle.Intersects(tileW.TileRectangle); // Creates A New Rectangle For TileNW tileNW.TileRectangle = new Rectangle((splatterTileX - 1) * Engine.TileWidth, (splatterTileY - 1) * Engine.TileHeight, Engine.TileWidth, Engine.TileHeight); // Tile Collision Detection Between Player Rectangle And Current Tile var tileNWCollision = player.Rectangle.Intersects(tileNW.TileRectangle); // Allow Sprite To Occupy More Than One Tile if (tileNCollision && tileN.TileBlocked == false) { tileN.TileOccupied = true; } if (tileECollision && tileE.TileBlocked == false) { tileE.TileOccupied = true; } if (tileSCollision && tileS.TileBlocked == false) { tileS.TileOccupied = true; } if (tileWCollision && tileW.TileBlocked == false) { tileW.TileOccupied = true; } // Player Up if (keyState.IsKeyDown(Keys.W) || (gamePadOneState.DPad.Up == ButtonState.Pressed)) { player.CurrentAnimation = AnimationKey.Up; if (tileN.TileOccupied == false) { if (tileNWCollision && tileNW.TileBlocked || tileNCollision && tileN.TileBlocked || tileNECollision && tileNE.TileBlocked) { playerMotion.Y = 0; } else playerMotion.Y = -1; } else if (tileN.TileOccupied) { if (tileNWCollision && tileNW.TileBlocked || tileNECollision && tileNE.TileBlocked) { playerMotion.Y = 0; } else playerMotion.Y = -1; } } // Player Down if (keyState.IsKeyDown(Keys.S) || (gamePadOneState.DPad.Down == ButtonState.Pressed)) { player.CurrentAnimation = AnimationKey.Down; // Check Collision With Tiles if (tileS.TileOccupied == false) { if (tileSWCollision && tileSW.TileBlocked || tileSCollision && tileS.TileBlocked || tileSECollision && tileSE.TileBlocked) { playerMotion.Y = 0; } else playerMotion.Y = 1; } else if (tileS.TileOccupied) { if (tileSWCollision && tileSW.TileBlocked || tileSECollision && tileSE.TileBlocked) { playerMotion.Y = 0; } else playerMotion.Y = 1; } } // Player Left if (keyState.IsKeyDown(Keys.A) || (gamePadOneState.DPad.Left == ButtonState.Pressed)) { player.CurrentAnimation = AnimationKey.Left; if (tileW.TileOccupied == false) { if (tileNWCollision && tileNW.TileBlocked || tileWCollision && tileW.TileBlocked || tileSWCollision && tileSW.TileBlocked) { playerMotion.X = 0; } else playerMotion.X = -1; } else if (tileW.TileOccupied) { if (tileNWCollision && tileNW.TileBlocked || tileSWCollision && tileSW.TileBlocked) { playerMotion.X = 0; } else playerMotion.X = -1; } } // Player Right if (keyState.IsKeyDown(Keys.D) || (gamePadOneState.DPad.Right == ButtonState.Pressed)) { player.CurrentAnimation = AnimationKey.Right; if (tileE.TileOccupied == false) { if (tileNECollision && tileNE.TileBlocked || tileECollision && tileE.TileBlocked || tileSECollision && tileSE.TileBlocked) { playerMotion.X = 0; } else playerMotion.X = 1; } else if (tileE.TileOccupied) { if (tileNECollision && tileNE.TileBlocked || tileSECollision && tileSE.TileBlocked) { playerMotion.X = 0; } else playerMotion.X = 1; } } I have my tile detection setup so the 8 tiles around the sprite are the only ones detected. The collision variable is true if the sprites rectangle intersects with one of the detected tiles. The sprites origin is centered at 16, 16 on the image so whenever this point goes over to the next tile it calls the surrounding tiles. I am trying to have collision detection like in the game Secret of Mana. If I remove the diagonal checks the sprite will pass through thoses tiles because whichever tile the sprites origin is on will be the detection center. So if the sprite is near the edge of the tile and then goes up it looks like half the sprite is walking through the wall. Is there a way for the detection to occur for each tile the sprite's rectangle touches?

    Read the article

  • Collision detections and how efficient they are

    - by Shadow
    How exactly do you implement collision detection? What are the costs involved? Do different platforms(c/c++, java, cocoa/iphone, flash, directX) have different optimizations for calculating collisions. And lastly are there libraries available to do this for me, or some that I can just interpret for my platform of choice? As I understand it you would need to loop through the collision map and find the area in question and then compair the input thing(e.g. a sprite) to the type of pixel that is in the questioned area. I understand the very basic idea, but I don't understand the underlying implementation or even a higher level one for that matter. It would seem that this type of detection, or any for that matter, is very costly. Tile map? Bit array? How are these created from an image(I would guess looping and doing stuff)? The reason I ask this question is to get a better understanding of the efficiency behind the scenes and to understand exactly what is going on. Links, references, or examples would be very helpful. I know this question is a bit longwinded so any help or references would be very welcome. Thanks SO!

    Read the article

  • Processing velocity-vectors during collision as neatly as possible

    - by DevEight
    Hello. I'm trying to create a good way to handle all possible collisions between two objects. Typically one will be moving and hitting the other, and should then "bounce" away. What I've done so far (I'm creating a typical game where you have a board and bounce a ball at bricks) is to check if the rectangles intersect and if they do, invert the Y-velocity. This is a really ugly and temporary solution that won't work in the long haul and since this is kind of processing is very common in games I'd really like to find a great way of doing this for future projects aswell. Any links or helpful info is appreciated. Below is what my collision-handling function looks like right now. protected void collision() { #region Boundaries if (bal.position.X + bal.velocity.X >= viewportRect.Width || bal.position.X + bal.velocity.X <= 0) { bal.velocity.X *= -1; } if (bal.position.Y + bal.velocity.Y <= 0) { bal.velocity.Y *= -1; } #endregion bal.rect = new Rectangle((int)bal.position.X+(int)bal.velocity.X-bal.sprite.Width/2, (int)bal.position.Y-bal.sprite.Height/2+(int)bal.velocity.Y, bal.sprite.Width, bal.sprite.Height); player.rect = new Rectangle((int)player.position.X-player.sprite.Width/2, (int)player.position.Y-player.sprite.Height/2, player.sprite.Width, player.sprite.Height); if (bal.rect.Intersects(player.rect)) { bal.position.Y = player.position.Y - player.sprite.Height / 2 - bal.sprite.Height / 2; if (player.position.X != player.prevPos.X) { bal.velocity.X -= (player.prevPos.X - player.position.X) / 2; } bal.velocity.Y *= -1; } foreach (Brick b in brickArray.list) { b.rect.X = Convert.ToInt32(b.position.X-b.sprite.Width/2); b.rect.Y = Convert.ToInt32(b.position.Y-b.sprite.Height/2); if (bal.rect.Intersects(b.rect)) { b.recieveHit(); bal.velocity.Y *= -1; } } brickArray.removeDead(); }

    Read the article

  • Collision between 2 objects of the same class

    - by user1826033
    Okay, so I have an enemy class(With rotation, position, texture and so on). I spawn a few enemies on the screen, they move around, but they overlap each other. So I tried to do a collision check between two enemies of the same class. But no matter what method I try, it isn't quite working. The best thing I tried was: foreach (Enemy enemy1 in enemies) { enemy1Pos = new Vector2(enemy1.position.X, enemy1.position.Y) foreach (Enemy enemy2 in enemies) { enemy2Pos = new Vector2(enemy2.position.X, enemy2.position.Y) if (Vector2.Distance(enemy2Pos, enemy1Pos) < 200) { enemy1Pos += new Vector2((float)(enemy1.Speed * Math.Cos(enemy1.Rotation)), (float)(enemy1.Speed * Math.Sin(enemy1.Rotation))); } } } This is not to exact code, so it might have some mistakes in it. Anyway when i implemented this solution, the enemies were not overlapping so everything was fine on that part. But, they were always moving to the right side of the screen. I've also looked up flocking etc, but I would like to know, how can I detect collision between 2 objects of the same class?

    Read the article

  • Resolving C++ Name Collision

    - by jnm2
    InitializeQTML is a function in QTML.h. I'm writing a wrapper and I would like to use the name InitializeQTML for the wrapper function: #include <QTML.h> public class QuickTime { public: static void InitializeQTML(InitializationFlags flag) { InitializeQTML((long)flag)); }; }; How can I reference the original InitializeQTML function from inside the wrapper function and avoid the name collision without renaming the wrapper?

    Read the article

  • Please help with bounding box/sprite collision in darkBASIC pro

    - by user1601163
    So I just recently learned BASIC and figured I would try making a clone of pong on my own in darkBASIC pro, and I made everything else work just fine except for the part that makes the ball bounce off the paddle. And yes I'm aware that the game is not yet finished. The error is on lines 39-51 EVERYTHING IS 2D. /////////////////////////////////////////////////////////// // // Project: Pong // Created: Friday, August 31, 2012 // Code: Brandon Spaulding // Art: Brandon Spaulding // Made in CIS lab at CPAVTS // Pong art and code © Brandon Spaulding 2012-2013 // ////////////////////////////////////////////////////////// y=150 x=0 ay=150 ax=612 ballx=300 bally=200 ballx_DIR=1 bally_DIR=1 hide mouse set global collision on //objectnumber=10 //make object box objectnumber,5,150,0 do load image "media\paddle1.png",1 load image "media\paddle2.png",2 load image "media\ball.png",3 sprite 1,x,y,1 sprite 2,ax,ay,2 sprite 3,ballx,bally,3 if upkey()=1 then y = y - 4 if downkey()=1 then y = y + 4 //num_1 = sprite collision(1,0) //num_2 = sprite collision(2,0) num_3 = sprite collision(3,0) for t=1 to 2 //ball&paddle collision if num_3 > 0 if bally_DIR=1 bally_DIR=0 else bally_DIR=1 endif if ballx_DIR=0 ballx_DIR=1 else ballx_DIR=0 endif endif //if bally > 1 and bally < 500 then bally=bally + 2.5 if bally_DIR=1 bally=bally-2.5 if bally<-2.5 bally_DIR=0 endif else bally=bally+2.5 if bally>452.5 bally_DIR=1 endif endif if ballx_DIR=1 ballx=ballx-2.5 if ballx<-2.5 ballx_DIR=0 endif else ballx=ballx+2.5 if ballx>612 ballx_DIR=1 endif endif //bally = bally + t //if bally < 600 or bally > 1 then bally = bally - 2.5 //if ballx < 400 or ballx > 1 then ballx = ballx + 2.5 //move sprite 3,1 next t if escapekey()=1 then exit loop end Thank you in advance for the help.

    Read the article

  • Simple collision detection for pong

    - by Dave Voyles
    I'm making a simple pong game, and things are great so far, but I have an odd bug which causes my ball (well, it's a box really) to get stuck on occasion when detecting collision against the ceiling or floor. It looks as though it is trying to update too frequently to get out of the collision check. Basically the box slides against the top or bottom of the screen from one paddle to the other, and quickly bounces on and off the wall while doing so, but only bounces a few pixels from the wall. What can I do to avoid this problem? It seems to occur at random. Below is my collision detection for the wall, as well as my update method for the ball. public void UpdatePosition() { size.X = (int)position.X; size.Y = (int)position.Y; position.X += speed * (float)Math.Cos(direction); position.Y += speed * (float)Math.Sin(direction); CheckWallHit(); } // Checks for collision with the ceiling or floor. // 2*Math.pi = 360 degrees // TODO: Change collision so that ball bounces from wall after getting caught private void CheckWallHit() { while (direction > 2 * Math.PI) { direction -= 2 * Math.PI; } while (direction < 0) { direction += 2 * Math.PI; } if (position.Y <= 0 || (position.Y > resetPos.Y * 2 - size.Height)) { direction = 2 * Math.PI - direction; } }

    Read the article

  • Separate collision mesh model?

    - by Menno Gouw
    I want to have another go at 3D within XNA. What I have seen from some other games that they just have a separate very low poly model "cage" around the environment model. However I can not find any reference to this. I have not that much experience with XNA 3D either. Is it possible to have this cage within each of my environmental models already? Lets just say I call the mesh within the .FBX wall and col_wall. How would I call to these different meshes within XNA? The player would just have a tight collision cube around. To make it a bit more efficient I will be making divide the map up by cubes and only calculate collision if the player is in it. Question two: I can't find anywhere to do cube vs mesh collision. Is there a method for this? Or perhaps it is possible to build my collision cage out of cubes in the 3D app and on loading of the models in XNA replace them directly by cubes? So I could just do box to box collision which should be very cheap and still give the player the ability to move over ledges on the static models.

    Read the article

  • melonJS: Entity and solid block on collision layer

    - by Arthur Halma
    Actually I have my player entity with 64x64 sprite animation and 18x60 hitbox also the map is maded by 16x16 tiles. When my player goes some way he can pass through blocks (but not all of them). For example there are 4 situations: Good (player can't pass the tile with isSolid property on collision layer) Good (player can't pass the tile with isSolid property on collision layer) Bad (player pass the tile with isSolid property on collision layer) Bad (player pass the tile with isSolid property on collision layer) Looks like melonJS checks only corners of hitbox instead of whole rectangle. Can anyone help me in this situation.

    Read the article

  • How does a collison engine work?

    - by JXPheonix
    Original question: Click me How exactly does a collision engine work? This is an extremely broad question. What code keeps things bouncing against each other, what code makes the player walk into a wall instead of walk through the wall? How does the code constantly refresh the players position and objects position to keep gravity and collision working as it should? If you don't know what a collision engine is, basically it's generally used in platformer games to make the player acutally hit walls and the like. There's the 2d type and the 3d type, but they all accomplish the same thing: collision. So, what keeps a collision engine ticking?

    Read the article

  • 2D collision detection and stuff with OpenGL

    - by shinjuo
    I am working on a simple 2D openGL project. It contains a main actor you can control with the keyboard arrows. I got that to work okay. What I am wanting is something that can help explain how to make another actor object follow the main actor. Maybe a tutorial on openGL. The three main things I need to learn are the actor following, collision detection, and some kind of way to create gravity. Any good books or tutorials to help get me in the right direction would be great.

    Read the article

< Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >