Solution [very simple][after hours]: I added rigidbody2d to boxcollider object and set mass for highest possible, it turned out that when object is many times heavier than other, then other will be pushed out of it much harder, and collisions look normal (tested on slowly moving object, but works), there is no going through collider like when the mass is ...
To make the if condition apply to both lines, put braces around them like this:
void OnCollisionEnter(Collision collision)
if (collision.gameObject.tag == "Cube")
Note: get in the habit of always using braces with if-, while-, and for-statements to make it explicitly ...
the box is slightly inside the first floor collider
Is this on purpose? If not, it's not the best solution but maybe you can increase the height of the box just by a bit, enough to make it "float" above the floors and not collide with the seam, but not too much to be noticeable while viewing the scene.
I ended up not "keeping the particles together" as I originally wanted because it made literally no sense computation-wise but using a bitmap of a white silhouette on a black background as a mask for each of the spaceship modules instead. A whole ship would be made of an array of those bitmaps stuck together. Whenever a module got hit I'd render an irregular ...
This problem usually occurs when you try to move a gameObject with a Rigidbody / Rigidbody2D component through an environment made of Colliders / Collider2Ds by manipulating its Transform. Don't do that. Changing the transform isn't "moving" an object, it's "teleporting" an object. Teleporting an object into a solid wall never ends well.
If you want to ...
It's hard to tell, but it looks like you are only ever testing for one collision. You need to maintain a list or collection of walls in order to test each one for the collision. That may be why it fails upon adding more walls. Once you have a collection of the walls you would test the player against each one before moving.
One way to solve the ...
Collisions are part of the physics update, which is typically handled in the fixed timestep loop (what you call "tick" here).
By handling collision detection and resolution at a fixed game time interval, you help ensure that the physics play out consistently even on very different hardware.
If you do physics on a variable timestep (like in the render loop),...
You need to 'interpolate' (commonly shortened to 'interp') your 'camera position' towards the object.
You have correctly identified a collision response event.
However, the name of your class seems to suggest that you are attempting to deal with this collision outside of either the player or the sprite that you have collided with.
Step 1 is to put ...
In 2D, we can use a trick that if we exchange the x & y of a vector and negate one of them, we get a vector perpendicular to the one we started with very cheaply.
Vector2 span = pointB - pointA;
Vector2 perpendicular = new Vector2(-span.y, span.x);
Vector2 offset = pointP - pointA;
float perpendicularDot = Vector2.Dot(offset, perpendicular);
I'm sure there are many solutions, but this is the first one I thought of. It's fairly simple and only involves basic algebra (which based on the method you proposed I assume you understand), but I'm going to go through it fully to try and ensure it makes sense:
First, ensure that px is between the values of ax and bx, and that py is between ay and by. If ...
A mesh collider is not the best solution here.
For one, they're unnecessarily expensive for collision with a flat ground plane. You're searching a polygon soup for a collision when you could be doing a cheap primitive check.
Second, a (non-convex) mesh is infinitely thin — it has no inside/outside that the physics engine can use to detect penetration.
We can think of collisions between a square and a circle as a collision between a rounded square and a point. Effectively, we strip off all the "round stuff" making up the disc, and add it onto the square instead (an operation called Minkowski addition).
If the the remaining center point of the circle is inside the rounded square, then the original square ...