New answers tagged

0

I recommend you look into how box2D works. Anyways use one of the below, most likely BeginContact. void BeginContact(b2Contact* contact); void EndContact(b2Contact* contact); Excerpt from the from the greatest source of Box2d knowledge know to mankind to explain why. iforce2d.com: Anatomy of a collision Impact 1, 2, 3 When fixtures are ...


-1

Option (C): change the screen resolution back to 800x600. Even if you don't do this, consider it as a thought experiment. In that case, it's the responsibility of the display to resize the graphics to fit its physical size, and then the responsibility of the operating system to give you pointer events at an 800x600 resolution. I think it all depends on ...


0

ClassicThunder's answer is correct, but I'd like to provide an example of an alternative/simpler means of achieving the desired effect. This is a simpler solution for rapid prototyping, cases where you don'thave access to a fully featured library, or for cases where you don't have access to a GPU (e.g. in embedded systems). To perform said mapping, you can ...


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


0

Continuous Collision Detection (CCD) and Ray Casting provide a specific time of impact (TOI). However using two AABBs and two triangles to create the 'hexagon' that covers all locations of the AABB's travel, you would only know whether TRUE/FALSE an intersection occurred - this isn't as useful when dealing with 'swept AABB' detection. Even with the images ...


36

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


-2

You can use a coroutines for this task, you should call this coroutine in order to damage you player, so you can set a time of invencibility with the waitForSeconds(3f); function bool finishedCoroutine = true; void OnTriggerEnter2D (Collider2D other) { if (other.gameObject.tag == ("Damage")) { { if(finishedCoroutine){ ...


0

I solved the problem myself! I now create the CollisionShape before applying the transformation. For transforming the RigidBody correctly, I extract the sacling-value from the matrix and give it to _rigidBody->getCollisionShape()->setLocalScaling. I then remove the scaling from the matrix and give that to the setWorldTransform. Here's my code: float ...


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


-2

Use a bool variable to make sure you only enter the if once, then reset it after you have left the trigger. Or dont reset it if it has to happen exactly once. void OnTriggerEnter2D (Collider2D other) { if (other.gameObject.tag == ("Damage")&&!isDamaged) { currentHealth = -5f; ...


-2

Create a collection and store a reference of the GameObject once it enters and remove the reference once it exits. For example, here I am utilizing HashSet. using System.Collections.Generic; private HashSet<GameObject> takenDamageFrom = new HashSet<GameObject>(); void OnTriggerEnter2D(Collider2D other) { // If damager and not yet damaged ...


0

I solved this by adding GetComponent<Rigidbody>().isKinematic = true; to my Arrow script in the OnCollisionEnter function.


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


0

It's possible the player object moves into a wall and the position is updated, then collision is detected and the players position is then corrected creating a "bouncing" effect. To correct this, compute your collisions prior to moving the player (or probably any object).


0

You could convert one of the OBBs to an AABB by applying the inverse of the first OBBs transform to both OBBs. Now the first OBBs is an AABB and the other is still an OBB, so you can use the AABB vs OBB function to test if they overlap. If the collision function returns a normal/position, you must transform them by the fist OBBs transform to put them back ...


0

Main ways to speed up frustum culling (and collision in general): simplified bounding: you have AABBs (check) fast collision functions: looks like you are doing this (in progress) spatial partitioning objects in the world: ??? Spatial partitioning gives the most speed up. Are you doing anything? Depending on game type, there are a ton of easy ways to get ...


0

As people said in comment, you need to provide more information. Here is a list of stuff you can check: Are Playercamera and Topcamera properly set in the editor Did you add your script to the objects you want to react to collision Did you add a collider component to these objects Did you check the "Is trigger" option (if yes, you should use OnTriggerEnter ...


0

I do not know which physics engine you are using but generally , if you want to things go smooth you have two decent ways: Dynamically, use forces to move and let the engine handle the collisions. Kinematically, use your own calculations to move and handle collisions. If you use kinematics for some of the huge bodies (you have to use kinematics for small ...


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.


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


0

I had to do this whilst learning basics of c++, its one of the first things we had to do for collision detection so hopefully I can be of some use Youll want to store the width and height of your screen in variables, and then perform a collision check to determine whether or not you have touched the screen and set the snakes position to, for example, the ...


0

You can use both particles (for the animation) and another system to really "paint" the surface. What I would do is use one or multiple invisible spheres that I would "trow" in direction of the canvas (with a Rigidbody, so it's affected by gravity), and then, detect collisions. You could also use Raycasting.


0

I can answer one of your problems enough to allow you to fill in the rest. I'm a C++ developer, so I'm not gonna be your best source of information. (For the heads up) To collision detect the border of the window, you'd say something like: int xMin = 0, xMax = this.width; int yMin = 0, yMax = this.height; if (player.x <= xMin) { // Arguments go ...


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


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


0

It's not clear what you are trying to achieve, but changing the < operators to <= might be a step in the right direction.


0

Your issue seems to be that you are only checking a single tile if your player is 32 or less pixels wide. That obviously does not work, because your player is taller than one tile. Hence, you need to remove the first easy-oit as it breaks the detection, and simply just rely on the looping method.


0

We have two cases, the first case being your ball is not colliding. Because of Newtons First Law your ball will have the originally random assigned velocity, \vec{v_{i}}. The second case is the one we are interested which is collision. Assuming we are operating in 2 dimensions then we can treat walls and edges of boxes as line segments. Using our current ...


0

Instead of defining a tile-type as "blocked" or "walkable" in general, define the four edges of a tile as "blocked" or "walkable" separately (a completely impassable tile would have all edges as "blocked"). That way you can define a tile-type like that upper cliff corner which can be entered and left through the west-edge and north-edge but not through the ...


0

In Tiled you can add layers. Use a layer for the ground level, elevation1, elevation2 etc. Define a ladder/stairs tile with a property (in the tileset tile property) to indicate the player can move up or down one layer.


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


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


0

When you have a bunch of adjacent box-colliders and expect that they behave like a continuous wall, then unfortunately they won't. As of version 5.3.4, this is an edge-case the Unity physics engine does not handle correctly. When a rigidbody collides with the edge between two box-colliders, Unity will register it as a collision with the edge of one collider ...


1

Unmark convex on the mesh collider. Convex mesh colliders will NOT have holes in them because that is required, by definition, to make them convex. Non-convex mesh colliders are only supported on kinematic rigidbodies and objects without rigidbodies, which should be fine for your usage.



Top 50 recent answers are included