Tag Info

New answers tagged

0

Spatial indexing works for circles of all sizes. Start with a simple grid which has been proven to be the most efficient anyhow in many tests. Use a 2d array of circle lists to conceptually divide the space to 2d-grid of squares. The grid should be spacious enough so that each circle can be in four squares at the same time at most. Each frame, you can: ...


0

The most basic response to a collision like this is, "Reverse velocity in the direction of the collision". If you bump something up top, change the upwards velocity to a downwards velocity. Leave the side-to-side velocity just the same. If your objects can move more than 1 "game cell" per frame, then you may also need to backtrack to the point of the ...


0

Should I go with abstract class or lean towards a component based entity system? What you are doing is fine. If its working and its fast enough, dont change it unless it doesnt meet all your requirements. All entities are updated, which makes the FPS drop. The first solution to this problem should also be: do I need to update all the entities? Is some of ...


1

To know if its worth it profile the collision loop and see if its faster after your changes. For sorting, a bubble or insertion sort will be faster than a quick sort if you reuse the same mostly-sorted array every frames. Quick sort is only faster if the list is completely random, for mostly-sorted lists you're better off with an improved bubble ...


2

You've inadvertently come across a form of broad-phase collision culling. Specifically, sort and sweep! Why not go all the way and use a QuadTree instead? Quadtrees recursively subdivide the space into quadrants, and only check collisions between entities which occupy the same quadrant. You can speed up your collision detections exponentially this way, with ...


1

You are not using the right variable to perform the collision time calculation. distanceXin is the distance between the two objects’ centres, whereas what you actually want is the distance between the two objects’ edges. Also, your code can be shortened and simplified a lot. Here is how I’d rewrite it: var boxCenterX = box.x + (box.width / 2); var ...


2

Touch screen record discrete points with a non-constant rate depending on how busy the CPU is and how reliable the hardware readings are. You need to "connect" those points as lines (old point from last game loop to new point) when checking for collisions and calculate line-line or line-circle intersection (or other type of line-object intersection). You ...


0

To complete @user55564 I give some more information about line segments intersection. In general you can check if any Intersection exist between your two polygon (even non-convex) as what I've described Here.


1

I think either AABB collision test or circle-circle is sufficient for your needs. Usually it is not necessary to have perfect pixel level precision in determining whether 2 objects hit. For circle-circle, have all your objects have a center x,y and a radius r; to determine whether 2 circles overlap: test (obj1.x-obj2.x)^2 + (obj1.y-obj2.y)^2 > (obj1.r + ...


1

You might be able to use a combination of the two approaches. You could turn off the collider of the thrown object when it's lifted, and use a simple, invisible, collider placed on the body like so: You could then fire this collider directly out from the body. It should be on the same plane as the player and the enemies, so it seems like handling hits ...


1

In general you can check if any Intersection exist between your two lines as below. Problem: Given n line segments; Report all(as k in algorithms) Intersections. You can implement any of these two algorithm in your desire language and use them. they take your line segments as input and return if any intersection ( Collision in your case) exists. Note: ...


1

Well on your question fixture def, you set sensor true which makes it ignore collisions. fixtureDef.isSensor = true; Unrelated but as a side note, I think you need to dispose your polygonShape at the end after creating everything. polygonShape.dispose()


1

You need to put your thinking level one step backward, and try to imagine that there is a different way than the quadratic solve. You can use iterative solving. This will not give you a perfect solution in all cases, but when many entities moves relative to each other with 2 or 3 contact points in average, this is the fastest and gives very good results. All ...


0

I have a simpler solution without using any physics or rigid bodies. For your character, it need to have both x,y position as position in screen and i,j as position on the grid with a flag called isMoving. When the character wants to move to i+1, j. Check if the cell at i+1, j is free. If so, set flag isMoving to true and set character i,j to i+1, j and do ...


0

Actually, there's no ready response for your problem. You can solve it in a variety of ways. If you are working with a "tile-like movement", you can simple check the next tile to see if is passable and only compute the movement if it is. It's a simple check if you have a array representing your world. Or a limited raycast if not. Also, Unity documentation ...


1

Your canCollideWith method should be so that s1.canCollideWith(s2) == s2.canCollideWith(s1)I think. If not it means that collision will differ according to your array order. And if both return the same results you can test that only once. Then in your code, you give two differents definitions of your canCollideWith method canCollideWith(Sprite) and ...


2

The most effective way to improve collision check speed is to decrease the number of entities that needs to be checked against. Spatial partitioning such as octree helps but you can make further improvements. Suppose if currently you have one big list of collidables contains objects and bullets and in each collision check step you are looping through all ...


1

Change your red square collision box to a circle collision (or a sphere in 3D, the same issue can happen in 3D).


2

Add a BulletCheck[BulletNo] == true condition. if ((BulletX[BulletNo] >= 103 && BulletX[BulletNo] <= 103.09) && (BulletY[BulletNo] <= -38 && BulletY[BulletNo] >= -45 && BulletActive[BulletNo]) == true) { BulletActive[BulletNo] = false; TurretTrial = TurretTrial - 5.0; if (TurretTrial ...


1

I think you and the commenters are on the right track. Ideally the hitboxes wouldn't have to be recreated on each attack (unless the nature of the attack were to change, maybe?). You could add something like this to every GameObject that can attack, along with a hitbox Collider marked as a Trigger. public class HitController : MonoBehavior { private Queue ...


0

From my short experience, these are my ideas/tips: What you are trying to do is called pixel perfect collision detection. Both player and texture should be inside a rectangle. Everytime Update function is called you should check "broad collision" to see if the two rectangles intersect (there is a Rectangle.Intersects method in XNA for rectangles) . If they ...


0

You are performing two raycasts, but only storing the result of the first one in hit. So the renderer you access to change material color to red is the renderer of the player, not the renderer of the tile. Add 'out hit' as a parameter to your second Physics.Raycast call: Physics.Raycast(user.transform.position,Vector3.down, out hit, 10);


1

What you need to do to implement sliding: 1) find the exact location of collision 2) find the normal of the collision 3) move the object to the location of collision 4) set the velocity of object opposite of the collision normal to 0; (or you need projection if you are working with non axis aligned stuff) 5) move the object again using the new adjusted ...


0

I think you might be able to achieve this in a 2D space by using multiple box colliders - or just just a range of x & y values, really. I spent a few hours in GIMP editing this up: Depicted is an open manhole that the turtles can fall in. Just a singular box collider would work for pits, but I used the screen wide colliders for illustration. For ...


1

It looks like you are using a matrix to rotate the image when it is drawn. This does not change the position values you have stored in your class, but it does affect how the image is drawn. If you want to know where the 4 corners of the image are drawn you will have to keep track of them yourself. Same is true of the bounding box. If the bounding box is to ...


1

As per @Krom Stern's suggestion, this is my solution to this problem. An incomplete, but working box cast algorithm for uniform grid: http://jsfiddle.net/d5ab67fj/1/. It currently is missing the end point cases and it only increment in X direction, but the algorithm itself is working. It will not miss any cells that the box would hit and it will not ...


0

I took a look at a number of implementations that are all based off of this paper: http://home.arcor.de/philippe.guigue/triangle_triangle_intersection.htm Here is one that I extracted and ran with your numbers - it returns no collision. You can look at main() to see the invocation with your test numbers. I have not done any more analysis than that. Good ...


1

Is this actually a problem? How much overhead would you incur by allowing the same check to happen twice in these cases? It is quite possible that the check would cause a bigger overhead than it saves. If you need to eliminate double results from the final set of collisions, I suggest that you do so after you have found them. The set of actual collisions ...


0

Given that you cast just one ray and that objects can take no more than closest neighbor tiles in any of 8 directions, you just need to expand your resulting list of tiles 1 tile in every direction. Either while you detect the tiles rays goes through, or after you have the whole list - depends on your needs/constraints.


3

Your problem is not the ray cast, but that your grid cell doesn't reflect its actual state or in other words it might contain objects that it doesn't know about. When a certain object intersects a grid cell, the grid cell should know about it, this way when an object intersect multiple grid cells each grid cell should have a reference to that object, this ...


1

Are you always doing triangle v triangle, or could it be triangle v sphere? Regardless, I think I would break it down into two problems: collecting candidate triangles for collision detection, and the detection itself. As you point out, when you hash into multiple buckets you need to identify and reject duplicates. I have two solutions, both of which I have ...


1

Are you on track, yes no maybe. Figuring collision sets (moving vs. stationary) is helpful, but will not bring you far. If you implement a general NxM solution that is efficient you may actually get more bang for your buck. For starters you should separate your collision detection from your collision response. This makes sense since you may want to collide ...



Top 50 recent answers are included