Tag Info

New answers tagged

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 ...


0

As I suggested in a comment on your other question (and as Tyyppi_77 suggested), you should look into the Rectangle structure. If you utilized it, then your collision code could be as simple as this: public void checkYCollisions(block[] platforms) { // assume player and block both contain a Rectangle property called "Bounds" // that represent each's ...


0

Here's my pseudo-code: When the player updates, get the position he wants to go. If it doesn't change, do nothing. Get the nearest blocks for that position, store them in an array or something. Go through that list / array, check for collisions If it collides, tweak the player's position until it doesn't collide with the block. For example, the player ...


-1

i used FixedUpdate() insted of FixUpdate() and problem solved.


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; ...


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 ...


0

The problem could be either: You've not marked your moving rigidbody with the right collision detection method. You need continious dynamic rather than discrete if you are moving your object with speed. Are both rigidbodies marked as kinematic? If so the event won't call.


0

Polygon A is overlapping polygon B if any of its vertices is inside B and vice versa. bool isOverlap(Polygon A, Polygon B){ foreach(Vertex v in A) { if(isInside(v, B)) return true; } foreach(Vertex v in B) { if(isInside(v, A )) return true; } return false } bool isInside(Vertex v, Polygon p) { //you can choose either ...


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 ...


0

The error comes from yTime and xTime. Since you are using a rectangle that is wider than taller, your xTime is always greater than your yTime. This is way when colliding in the x directions it works, and when colliding in the y directions, the wrong thing happens. You can test this by swapping the width and height dimensions of the box, and the error will ...


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 ...


-1

Define an interface IWall. using UnityEngine; using System.Collections; public interface IWall { void OnCollisionEnter(Collision collision); } It is nice to separate the vertical and horizontal walls in to two classes as their logic for handling collisions is different. VerticalWall using UnityEngine; using System.Collections; ...


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.


0

I'm just learning SpriteKit myself, however I think the following would be faster: - (BOOL)checkCollisionForSpikePoint:(GCPoint)spikePoint ballCenter:(CGPoint)ballCenter ballRadius:(CGFloat)ballRadius { CGFloat hypotenuse = sqrt(exp(spikePoint.x-ballCenter.x,2) + exp(spikePoint.y-ballCenter.y,2)); ...


0

You have to use OnCollisionEnter2d() method here so collision detection happen for one time only. If you want any collision detection then there is no requirement of rigidbody. If I can't able to understand you question then ask it specifically.


0

I think most of your problems might be solved by understanding the use of category masks. Simply set the masks to ignore contact and collision between the sword and player categories. Specifically, this is done by assigning unsigned integers to the categoryBitMask, collisionBitMask, and contactBitMask properties of the SKPhysicsBody of the SKSpriteNode in ...


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 ...


0

Stacking Issue Regarding the stacking issue, I am not sure how your class is setup, but I would consider handling the positioning of the stacked elements based on an indexed approach. For Instance (pseudo code): class Skewer : MonoBehaviour { public List<SkewerElements> skewerElements = new List<SkewerElements>(); public float ...


0

Consistency is crucial for smooth collision detection. I recommend using the bottom center point for rectangular collision as well as slope collision when colliding against the ground. For colliding against walls, you can use points that are in the center left and center right of your sprite. Another way to think of it is as though your sprite has a ...


0

Problem 1: It's possible you need to subtract your offsets from your coordinates rather than add them. This would explain why collision doesn't work when scrolling. The correct operation (addition or subtraction) depends on how your offset is defined and used elsewhere. If your player position is in world coordinates and the offset represents the ...


0

The simplest means of determining if there is contact after your touches finish is to alter the category of the "ball" to a category that registers contacts with the "bucket". That is to say, your ball would have a category that ignores the bucket until the ball is dragged and the touches end (touchesEnd method), at which point the category of the ...


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 ...


0

The simplest possible solution would be to maintain the horizontal velocity, and flip the sign of the vertical velocity, after multiplying it by an elasticity factor. vec2 velocity; vec2 position; position += velocity * dt; if (collision) { position = adjust_position(); // to not collide anymore velocity.y = -velocity.y * elasticity; } If you're ...


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

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 ...


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 ...


0

You can send messages to each entity in the collision, containing the collision_type of the other object, it's mass and velocity at the time of collision, and the contact point on the messaged entity. Entities handle the messages for collision_types they want to respond to, and ignore the others. Also, a couple of nice optimizations can be done. 1) Start ...


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 ...


0

Treat the tilemap as purely graphical data, and use some other structure to resolve collisions. In your case, you can define the boundaries of your roads using edges (segments). You have a vector (line) representing the player's movement, and you want to know if this line will intersect some wall during this timestep. Since these walls are represented by ...


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) ...


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 ...


0

Multisampling, as the people over at Metanet call it. Basically, you do a racket/ball collision test at frequent enough time intervals between frames such that the ball can't be passed by the racket without a collision being detected. This gives a rough estimate as to when the collision occurred, after which you can start subdividing your time step to find ...


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 ...


0

What you could do is give the racket a defined constant "range" that is +- half the distance the ball moves every update. This way the ball would never pass through the racket. This will of course result in minor inconsistencies with the ball's rebound trajectory, but you'd have to test this out to determine their actual effects. Yes the logical size of the ...


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 ...


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 ...


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.



Top 50 recent answers are included