Hi,
I need point physics that forms a polygon collider, since this is not built into Unity, I wrote my own, but my collision physics is ugly:
void VelocityChanges(Vector3 directionNormalFromCollisionPointNormalized,
Rigidbody2D rbPoint1,
Rigidbody2D rbPoint2)
{
//=========================================================== Detect forces
float forceRb = Vector2.Dot(rb.velocity, -directionNormalFromCollisionPointNormalized);
float forceRbPoint1 = 0;
float forceRbPoint2 = 0;
if (rbPoint1 != null)
{
forceRbPoint1 = Vector2.Dot(rbPoint1.velocity, directionNormalFromCollisionPointNormalized);
forceRbPoint2 = Vector2.Dot(rbPoint2.velocity, directionNormalFromCollisionPointNormalized);
}
//=========================================================== Detect forces
//=========================================================== Calculate forces
CheckNegetiveDirectionAndAddForce(rb, directionNormalFromCollisionPointNormalized, forceRb, forceRbPoint2, forceRbPoint1);
if (rbPoint1 != null)
{
CheckNegetiveDirectionAndAddForce(rbPoint1, -directionNormalFromCollisionPointNormalized, forceRbPoint1, forceRb/2f, 0);
CheckNegetiveDirectionAndAddForce(rbPoint2, -directionNormalFromCollisionPointNormalized, forceRbPoint2, forceRb/2f, 0);
}
//=========================================================== Calculate forces
}
void CheckNegetiveDirectionAndAddForce(Rigidbody2D rb_,
Vector2 direction, float abserbedForce,
float force2, float force3)
{
if (abserbedForce < 0) { abserbedForce = 0; }
if (force2 < 0) { force2 = 0; }
if (force3 < 0) { force3 = 0; }
rb_.AddForce((abserbedForce + force2 + force3) * direction, ForceMode2D.Impulse);
}
What is the problem: when colliding, I determine the point of contact with another collider and move it there, this works fine, but then I need to apply forces and for example gravity constantly acts on the point it enters the collider and then is pushed out of it. The result is that the point constantly trembles (wobbles, shakes).
It is because of springs between the points, but I don’t understand how to fix it.
Unity in its rigidbody2d collisions makes it so that the force does not affect the collider at all, if the object is already on the surface of the collider, I want this for myself
I’d be grateful for any ideas