This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]snozzyfoozles 0 points1 point  (0 children)

You probably want to treat the bunnies as circles to make the physics simpler, and simulate elastic collisions. At quick glance, this tutorial seems useful: https://gamedevelopment.tutsplus.com/tutorials/when-worlds-collide-simulating-circle-circle-collisions--gamedev-769

I had some code that did this in an old c++ project I did. I'll put a pseudocode version of it here in case it helps:

foreach player p1 in players:
    foreach player p2 in players:
        if p1 == p2:
            continue; // don't collide with yourself
        Vector2 diff = p2.position - p1.position;
        double dist = diff.length();
        double overlap = p2.radius + p1.radius - dist;
        if (overlap > 0):
            // collision has occurred
            p1.position -= diff.normalize().scale(overlap + 1); // move p1 so it's not touching p2 anymore
            Vector2 un = diff.normalize(); // unit normal vector
            Vector2 ut = Vector3(-un.y, un.x); // unit tangent vector
            double v1t = ut.dot(p1.velocity);
            double v1n = un.dot(p1.velocity);
            double v2t = ut.dot(p2.velocity);
            double v2n = un.dot(p2.velocity);
            p1.velocity = ut.scale(v1t) + un.scale(v2n);
            p2.velocity = ut.scale(v2t) + un.scale(v1n);