Hey.
I have two “quad” that are both “Rigidbody2D” and “BoxCollider2D”, and they collide.
However when I move faster or, for example, back to the corner of the screen, they pass trough each other when I’m clicking, when i’m not clicking, they not stay one above the other, but I want to resolve the situation when I’m clicking. It’s only happens in that two cases, against the wall (limits of the screen) and when I move faster.
Clicking alone should not affect whether colliders interact. I’m still suspicious of what you’re doing with those clicks that might be causing the problem; maybe post the code? Sufficient speed can mess up colliders if they pass through each other in a single physics update; this is unusual unless the colliders are moving very fast relative to their size. You can fix this by setting Rigidbody2D’s collision detection mode to continuous, at a performance cost.
I’m dragging A against B… When B beats against the wall, the A goes up of the B (with mouse click) and if i’m without mouse click, the A get off the B… But i want that, on mouse click, the A don’t goes up of the B.
A and B are two quad’s, Box Collider’s 2D without triggers, and RigidBody2D without kinematic.
That doesn’t mean anything. What, exactly, is being done to A? Just post the code or something. I’ve been asking you the same question for four days. Nobody can tell you why A is riding up on B without knowing what’s moving A. Dragging is input. We need the output to A.
Okay, your problem is in “transform.position = curPosition;”. That line of code hard-sets the position of the object. Directly setting the position ignores any colliders in the way.
There’s several ways you can change it to act more like what you want.
If the colliders are simple (circles or world-parallel rectangles), you can do an overlap check before you set the position, and don’t set the position if there’s an overlap. See Physics2D.OverlapCircle, for example.
Otherwise, the simplest thing to do is probably just to not set the position while you’re colliding. So you could add code in OnEnterCollision2D and OnStayCollision2D that sets a flag, and don’t set the position while that flag is in effect. Or better yet, set the position to tangent the collision point, so there’s no overlap at all.
Another tactic would be to use AddForce instead of setting the position. This can make the object move towards the drag point with complete physics support, but it will tend to lag your finger and will tend to retain any momentum it built up while moving.