Hot answers tagged

6

I suspected OP already knew this approach so I mentioned it in a comment as just a starting point, but I'll try fleshing it out a bit more... Most physics engines divide dynamic objects into two groups, "awake," and "sleeping." Objects sleep when they sit at rest, and wake when moved or accelerated by some outside influence. A sleeping object behaves like ...


3

You want the 2D version of the method: OnCollisionEnter2D Collisions with a Collider2D/Rigidbody2D won't send the "OnCollisionEnter" message, only "OnCollisionEnter2D"


3

On line 161 you return too early from FlattenPoints. Move the return statement outside of the for loop and everything appears to work correctly.


3

Have you considered playing the sound when the direction of the ball changes? Or like add that as a condition, in addition to the already "collide with object" condition.


2

The Pygame Rect already comes with a few collision detection functions that may just do what you need: pygame.Rect.contains: test if one rectangle is inside another pygame.Rect.collidepoint: test if a point is inside a rectangle pygame.Rect.colliderect: test if two rectangles overlap pygame.Rect.collidelist: test if one rectangle in a list intersects ...


2

I'm not sure if its a good solution but i use to add x, y and z (gonna call this XYZ from now) and store it in a linked list with an object identifier and the average side size (we gonna asume that, in this example the object is a cube of 20x20x20 so 20*3/3 = 20). //PSEUDOCODE MYOBJECT ob(/*id*/ 1, /*size*/ 20, /*x*/ 30, /*y*/ 12, /*z*/ 4); ...


2

I see two ways to do this: An array on the enemy that keeps track of what fire ball has hit it and check against it every time there is a collision. As you have already suggested: an array of identifiers of enemies that have been hit by the fireball. Now you have to ask "Who's responsible for calculating the damage of the fireball on the enemies?", if ...


2

Most games use quadtree structures to manage the colisions, you should read about it. Anyways, if you are having lag after X levels is possible that you are storing all the objects and checking them out every loop, and not just the object in the current scene or level.


2

The idea is practically the same for 1D, 2D or 3D or any other dimension. First let's talk about a 1D scenario: We have two segments along x axis, and we know their start and their ends. let them be s1,e1,s2,e2. So what's the requirement for these two lines to overlap? well, we can say the first line should start before the second one ends, and vise versa. ...


2

One issue with your implementation is that you only check if det is smaller kEpsilon, but there is no guarantee that det is positive. You want to check if(det<kEpsilon && det>-kEpsilon) So that might explain the false positives. The way this algorithm works is by basically figuring out "when" the ray will hit the triangles plane and then ...


2

If I understand the problem correctly, you were close to properly solving it. Your approach with the normals is what you want, but instead of only saving the normal of the last collision, save a list of normals from all current collisions/overlappings. Then, play the sound whenever the new normal of the new collision is not yet present in the list. In ...


1

Ok, I'm piggy-backing on Skitskraj's answer here so if you like mine, upvote his/hers too. Solution: Play the sound only if there is a new contact and there is a significant velocity change. I would suggest using the postSolve callback on the first iteration of the collision to determine if the impulse is above some threshold value required to generate the ...


1

I asked just this question on SO a while ago, same language aswell, and no one didn't really care, so when I found the solution I didn't really bother to put it up there, but now more people are interested and I am glad for that, so now I will post the answer here. Here's my original code, it's the exact same thing as yours, just a bit more clear of what ...


1

This is because the ball -at high velovity- will be before the box in one frame and behind the box in the next: so no collision has occured. To fix this make sure the collision is continious or interpolated. Set your collision mode to DynamicContinious for high velocity objects or Continious for fast objects. This does have a bit of an impact on ...


1

This is the part I currently need to work on for my own game.. What I've reasoned out so far is that I can have a CollisionBox on the GameObject which contains all the collision boundary information. Collisions are checked by GameObject.isColliding(other) - where the two CollisionBoxes compare whether they intersect. if (gameObject.isColliding(other)) { ...


1

You would need to convert your texture into a rectangle, which is just a position and size. Your entity that is displaying the texture, should have the position, and the texture itself could potentially hold the size (this is completely dependent on how you are currently doing your spritebatch draw calls). It would end up looking something like: Dim ...


1

From your code: for (k = 0; k < bullets.Count; k++) { for (k = 0; k < meteors.Count; k++) { if (rocket.rectangle.Intersects(meteors[k].rectangle)) { meteors[k].isVisible = false; } } } You use the same iterator in both for loops. It also looks as though you are reusing that (global) iterator from ...


1

Best thing you could do here, is just convert your Rectangle variables into a read-only property. This way you only need to update your position, and your Rectangle will always be up to date: class Bullet { public Rectangle rectangle { get { return new Rectangle((int)position.X, (int)position.y, 10, 5); } } class Meteor { public ...


1

A standard parametric ray equation is r(t) = p + td. The origin point is p and d is the ray direction. So, that algorithm gives you t and you know p and d already. Therefore you can compute ray (or vector) r(t), and then take its magnitude |r(t)| to obtain the distance to triangle (intersection). PS. You may need to normalize your direction vector d first. ...


1

This is almost a comment, but too long so i'll post as an answer. Hopefully it will help. There's a design flaw i think in your code : you solve on x then on y but in both cases you set both x and y... So when you solve on Y, you 'break' the solve on X you just made. I think you should split the collision detection and its resolution : (pseudo-code) ...


1

I don't want to replicate Steven's answer, but I want to include images. The correct answer is to use OnActorBeginOverlap, as you were marked to. If you are not receiving the correct triggering dispatch, it's almost sure that you don't have the correct layering configuration. You can do that using the Collision subpanel in the Details panel of your object ...


1

My initial answer to this is: Do not use an ellipse, unless you have a really good reason. My second answer would be: If you want to detect collision with complex shapes, use a library and/or engine. My third answer would be: If you want to see real progress on a game project: Use a set of good libraries, minimum. And lastly, If you want to actually finish ...


1

They are describing how to get the nearest point on the moving circle trayectory to the "checking" circle center, without using vector math. Or better , using it but without telling that. var t = dx * distToBubble.x + dy * distToBubble.y; is simply the dot product of the moving vector (velocity vector) and the direction vector from moving circle. Hope ...



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