Tag Info

Hot answers tagged

3

You need to add a BoxCollider2D component to your GameObjects. http://docs.unity3d.com/ScriptReference/BoxCollider2D.html From the Unity docs for OnCollisionEnter2D Sent when an incoming collider makes contact with this object's collider A Rigidbody2D just tells a GameObject how to interact with the physics engine. It doesn't provide a collider for ...


3

For your first question you can optimize your method by only checking collisions with the border bubbles (only the bubbles that are actually exposed and not ones that are entirely surrounded). However, you can optimize this even further by using the fact that you know the coordinates of the bubble to find out approximately (or precisely, with some math) ...


3

Create an invisible box in front of the fan. Then check if some object is inside that box. Apply movement to that object. This can be done in unity quite easily. Create Empty gameobject Select the new gameobject Add Component-> Mesh -> Mesh filter Select from inspector -> Mesh filter -> mesh and set it to "cube" ( or what ever shape you want ) Add ...


3

Figuring out the correct solution to multiple collisions between overlapping (or perfectly aligned rectangles) is not trivial, and most solutions will have problems. I'm not even sure if there is an actual correct solution. Reading this question made me think that the problem could be solved by not letting the problem exist in the first place! "The problem" ...


2

I admit I've never successfully written a collision resolver, but I have a suggestion. Your problem is that you have two valid contacts that resolve a collision between the circle and a rectangle. On their own, each contact will solve the collision, but when there are two contact occurring in the same cycle you will have to pick one. You can't apply both ...


2

Several possibilities : 1) use small collision maps for each different tile. It does not need to be very precise, small maps like 8x8 might be enough (depending what you need). You can do some interpolation to smooth it out. Here is an example : Instead of using only occupied / non-occupied state for the collision map, you might also consider using ...


2

getBoundsInParent() returns the bounding box around the shape — a rectangle. The built-in intersects() check works only for rectangular shapes, not for circles, polygons, etc. For these, you'd need to implement the check yourself.


2

If your platforms are isolated use Tags. Each object and prefab in the Unity game world can be interacted with differently depending on the tag they have. For a wall of any kind simply tag it as "Wall" and code it with this is mind when making collision detection on your main character. For a platform, guess what, tag it as "Platform". You can then ...


2

Your problem is that you are checking for a collision and then stopping, this means that if your frame places you to far into an object you are now stuck. To solve this you have to solve the equation of exactly where both object were when they hit one another. So you have to find where the following is true: |t*v1+p1-t*v2+p2)|=|r| where t is time v is ...


1

I will assume that the player collides with the ground only on the middle point. We can do an approximation of the height of the terrain at a given point with this: double x = 4.6; double relativeX = x / widthBetweenPoints; int terrainIndex = Math.floor(x); double ratio = relativeX - terrainIndex; int y = Points[terrainIndex] * (1 - ratio) + ...


1

Collision doesn't need to care about tiles at all. If a tile is just a shape of lines, your "tile collision" is really just collision against those specific lines. You can also use collision against arbitrary shapes defined by mathematical functions - like curves - which are represented by tiles. Tile collision in this case means determining which tiles the ...


1

You should use raycasting to check for visibility. Each raycast is expensive, so stagger the visibility checks for different enemies (they don't all have to see the player on the same frame)


1

You should write a method that checks the visibility. It follows the definition: http://en.wikipedia.org/wiki/Visibility_%28geometry%29 There are a lot of techniques to do that. Therefore, I reccomend you searching on the web which approach would fit best in your problem.


1

Android does not limit your options when it comes to collision detection. Here is a nice article about SAT collision detection: http://www.codeproject.com/Articles/15573/D-Polygon-Collision-Detection That implementation also has the nice feature of being tunneling free. That is, if two object with very high speed intersect each others paths in such a way ...


1

Instead of checking a single block for collision, you could keep a list of blocks and then iterate through the list and perform collision responses for each block in the list. Like this: public void checkYCollisions(block[] platforms) { if (position.Y >= 700) grounded = true; else grounded = false; float Xradius = Width / 2; ...


1

Remember that SpriteKit's physics system is based on "SKPhysicsBody"s, which are added to "SKSpriteNode"s. Those physics bodies, however, needn't be attached to visible nodes. The simplest method is to create a SpriteNode with no actual sprite or visible body, add it as a child to the area you want on the visible shape, and categorize it differently from ...


1

A simpler way, that will also speed up your program, is to check if your circle is moving towardas the other circle before check for a possible collision. You can do in it in this way: vector2 p; p.x = other.position.x - your.position.x; p.y = other.position.y - your.position.y; if(p.x*yourSpeed.x + p.y*yourSpeed.y > 0 { //check for collision; } look ...


1

Well, Mike C already gave you a simple answer, I am going a bit deeper: First you need to a way to filter the results by proximity (this is to prevent lag when looping throught the objects) I advise using some sort of hashmap to sort the objects. Calculate them on a grid with their X and Y coordinates and then just Iterate between the near objects, if ...


1

As per Andy's comment: Nevermind, I fixed it. I just had to take out the p.setCenterX(center.x);p.setCenterY(center.y); out of the render function.


1

You need only simple collision detection for something like this: You could just compare the X-coordinate of the nearest wall with that of the player when the player throws a punch. Something along the lines of if (wall.x - player.x <= 50 && wall.x - player.x > 0) { // The wall is in a good position! } else { // The wall is out of ...


1

A high-powered family of algorithms you may need to look into are all "clustering" algorithms. These algorithms find groups of data points which could be Cartesian points or any other property (color, weight, etc.). See K-means Clustering for one such algorithm. It's not a terrible algorithm to run in real-time, depending on how many entities you need to ...


1

The other's have suggested kd tree's but I think that a more appropriate data structure for you would be using an R-Tree which is specifically for retrieving collections of near objects. You can find out more here: http://en.wikipedia.org/wiki/R-tree


1

A kd-tree or AABB tree is a great data structure, if the objects are going to be static, or mostly static, as they are not cheap to update. But it seems like those structures would be more useful to find what's around a certain point, rather than to figure out the largest cluster of objects. For that, I'd use a simple grid. Have each object register itself ...


1

The way I might approach it is to create a list of all possible hex center locations during the initialization stage before the game loop starts. Then during the game loop, if there is a mouse click within 1.5 tile radius (or whatever dist you think is approp) of a white tile, simply iterate the list and find the closest list Point to the click point. If the ...



Only top voted, non community-wiki answers of a minimum length are eligible