Hot answers tagged

38

Typically (even for 2d games) there is a separate coordinate system for the game that is independent of the resolution, this is typically referred to as the world space. This allows you to scale to an arbitrary resolution. The easiest way to achieve this is use a 2D Camera, which is essentially a matrix that defines the transition from world space (your ...


5

Convert your image to grey-scale. Make sure you have no two states that have the same grey. (You have to tweak the image.) Have an infrastructure that maps the grey colour to a state. Then when you mouse-over the map, pick the pixel colour that is under the mouse pointer, and search for it in the map. You'll know what state you want to select this way.


3

According to the Unity documentation for OnTriggerEnter2D the trigger is "[s]ent when another object enters a trigger collider attached to this object (2D physics only)". The function should only be called once per entrance. You could gather further data by logging the number of calls to OnTriggerEnter2D and OnTriggerExit2D. Perhaps some funny business is ...


3

I'm not really a fan of this : if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask { firstBody = contact.bodyA secondBody = contact.bodyB } else { firstBody = contact.bodyB secondBody = contact.bodyA } and prefer to do the following: let contactMask = contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask ...


3

Edit The observed behavior of the ball going through the paddle prompts me to check your collision detection statements, and I believe they are the problem. The condition if (ballx == x + (P1W / 1.0)) will only return true if ballxis exactly equal to a specific point of your paddle. What you want to check is if any part of your ball overlaps any part of ...


2

When you have multiple collisions if you rectify your collisions from closest to farthest away from the center of each rectangle involved, you will not have the issue of "hanging." 1) Find all the colliding rectangles 2) If there are more than one (depending on your use case this can be frequent or infrequent), find the closest. 3) Resolve collisions ...


2

Another option would be: On each input mouse movement event, move the in-game mouse cursor by the number of game pixels corresponding to the number of pixels in the mouse event. This comes naturally for 3D games that lock the real mouse pointer to the center and rotate the aim direction by an amount corresponding to the input mouse movement, but you could do ...


1

I've been thinking about this problem for a long time and looked at some of the answers here and on other forums. I came up with the following idea: Suppose the circle has radius R. When looking at cases where the circle collides with the AABB , the center of the circle has to fall within a certain area around the AABB. The extreme cases are when the center ...


1

It isn't that clear what you mean with top and height, but let's say you have your character's x, y, width and height, and so you do for the wall (assuming the x and y values are on the top-left corner of the character/wall, and the y axis gets greater when going downward) if (character.y + character.height > wall.y && charcter.x + ...


1

I assume that you are calling update() once every frame, before you draw the frame. Your problem is that you are doing either the collision correction or the movement every frame. You need to do both. What's happening is: Your character checks if it is below the screen bounds, it isn't So it moves below the screen bounds, draws for one frame below the ...


1

I think you need some documentation about collisions. It seems you want to check the collision between 2 hitbox on a 2D game: if (rect1.x < rect2.x + rect2.width && rect1.x + rect1.width > rect2.x && rect1.y < rect2.y + rect2.height && rect1.height + rect1.y > rect2.y) { // collision detected! } But you're ...


1

Physical 4 State Linear Translation---------- FORCE- The amount of force the ball was hit.(kg) ACCELERATION- That same force divided by the mass of the ball (Force/Mass) VELOCITY- Acceleration over time is Velocity (Force/Mass)*T POSITION- Velocity over time changes the position (Force/Mass)*T^2 DIRECTION Position is determined by direction on ...


1

Assuming that you mean the x,y passed in is the point on the ball that you hit. A bit like the cue position when you hit a ball with a snooker cue. You can do it with a bit of vector maths. // create direction vector for ball to go. var dirX = ball.centerX - x; var dirY = ball.centerY - y; // convert dir to unit vector. this'll make it ...



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