New answers tagged

0

First, this line: float dotProduct = (_one->velocity().x() * collisionNormal.y() + _one->velocity().y() * collisionNormal.x()) * remainingTime; is calculating the wrong quantity (it should be x * x + y * y). Second, if you want to slide, you simply need to set the component of the velocity parallel to the normal of the collision surface to 0, and ...


2

You are only checking th i-th bullet with the enemy of the same index and not with every enemy there is. You should do something like this for (int i = 0; i < Bullet.Bullets.Count; i++) { for (int j = 0; j < Enemy.Enemies.Count; j++) { if (Collisions.IsColliding( (int)Bullet.Bullets[i].position.X, ...


0

If you have several platforms connected in Unity your character might sometimes, (not always) slow down/stop. There are 2 fixes that might work for this : 1. Circle Collider If you have a box collider on your moving object/character, the corners of the collider might collide with the corners on the connected platforms, causing the object to slow ...


1

A couple of things: You should avoid creating, and recreating the Color arrays. Find a way to create them once and avoid GC. The textures are not generated by the GPU and won't force it to synchronize with the CPU, but you should avoid copying and/or sifting through it on the CPU if at all possible. As a direct answer to your question, the Rectangle ...


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


0

Well, it is most probably because you have your Trigger (Sphere) collider attached to the same object where your Sword would work. So it is showing the same behaviour as sword hits the enemy, because of same object and script. What you can do is , Make a parent gameobject in which player and another gameobject should exist as children. Attach two scripts ...


3

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


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


0

I created a simple platformer that used rectangle collision in order to detect if the player is currently colliding with a tile. I made the game in c# but I believe the concept will be the same for Javascript. Here are the steps I took: 1: Create a new class named Tile 2: Generate a list of Tiles in order to fill up the tilemap 3: Run a loop through each ...


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


0

I'd just like to add, for completeness, that you could always try using a single collider for your GameObject, then infer what side it was on from the collision point. You can access the point like so: void OnCollisionEnter(Collision collision) { foreach(var contact in collision.contacts) { Vector3 pointOfImpact = contact.point; } }


0

Actually and hopefully you did attach all three colliders on same gameObject. What you have to do is create 3 children gameObject and attach one collider to one child. In that way you can detect what you want. Attach a Jon's script to each collider then in my OnCollisionEnter you can from which collider collision is occured through tag, any attribute or ...


0

You can always use OnColliderEnter (or OnCollisionEnter2D), and store the first collision. So consider something like this: Collider FirstCollider; int CollisionCount; void OnCollisionEnter(Collider collider) { if (FirstCollider == null) FirstCollider = collider; CollisionCount++; } void OnCollisionExit(Collider collider) { ...


0

The solution is simple as that: P = Circle center r = radius or the circle You get the closest point from the circle center to the polygon (C) (I assume you got that already) Get the distance from the closest point to the circle center (D) = C-P Normalize that distance to get the unit vector (N) Get the signed distance to the edge/vertex and take the ...


0

Something that you could consider is using B├ęzier Curves. Find some way to determine the points that generate a curve that fits each corner of your race track. Use the function for that particular curve to calculate collision. Here is some more reference for using Bezier Curves in the context of game development.


0

Try changing the material of your box colliders. Also, I found a similar thread in Unity forums. That's about 2D, but the problem seems to be the same.


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

It turns out all i had to do was increase the thickness of the box collider.


0

May no be a greater answer to your question, but have you tried using GM:S's physics engine? You can simply assign physics fixtures to the objects and let the program do the collision for you, if these two objects are the only ones you want collision with, you can just give physics properties to these two and everything else stay in your original design. ...


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


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

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

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


0

Since you're not strictely looking for code-based answers you might want to try: Of course assuming it doesn't constrict your level design. (Skitskraj's answer is pretty good too tho)


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

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


0

I'm a VB person, so I don't know the C syntax, isn't there a For Each loop you can use instead of using your k variable? For each will loop all, it doesn't care how many.


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


0

Looks like you are only updating the position vector. When you are checking for intersection the rectangles haven't moved. You could change the rectangles x,y values as well but you have to change your spriteBatch.Draw call and omit the position. You might be tempted to skip the position vector entirely and only use the rectangles position. I don't think ...


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.


0

I've just figured out a decent system wich works quite perfectly; So, first of in your main update method you manage the inputs like usual: l = Keyboard.isKeyDown(Input.KEY_A); r = Keyboard.isKeyDown(Input.KEY_D); u = Keyboard.isKeyDown(Input.KEY_W); d = Keyboard.isKeyDown(Input.KEY_S); if(l){ setXvel(-speed*delta); //Note: you dont have to use ...


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


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

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

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


0

Disclaimer: This answer is 100% subjective, it is related to code design personal preferences and might not be the best answer. I would delete InteractionsManager class. The idea of having 2 lists (arrays) and checking for collision in a loop is nice, but you can do that on your Screen class. (just create a checkCollisions() method and call it on ...


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


0

I am not experienced in Cocos2D or JavaScript, but using color-patterns is very common on Java game development, and I am sure JavaScript will be almost the same. Here you have an example that does this: -Every static int on capital letters is a color. (Each element in the game is assigned a color) -loadBinary() reads levels.png and creates a new element ...


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.


0

A completely different aproach may be: consider your "fireball" (or area weapon) damage as HP per second. And every step you calculate the damage in this way enemy.HP = enemy.HP - firebal.damagePerSec * dt where dt is your frame delta time. I know this is a bit out of target , as your question is very specific.


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


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



Top 50 recent answers are included