Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Detect specific rope collision.
#11
(19-11-2020, 02:24 PM)canerozdemir Wrote: Oh, I missed that one. However, the outcome is still the same. FPS drop happens and the game becomes unplayable. This is the code: 


Code:
public class RopeCollision : MonoBehaviour
{
    private ObiSolver _solver;

    private ObiSolver.ObiCollisionEventArgs _collisionEvent;

    private void Awake()
    {
        _solver = GetComponent<ObiSolver>();
    }

    private void OnEnable ()
    {
        _solver.OnParticleCollision += Solver_OnParticleCollision;
    }

    private void OnDisable()
    {
        _solver.OnParticleCollision -= Solver_OnParticleCollision;
    }

    private void Solver_OnParticleCollision (object sender, ObiSolver.ObiCollisionEventArgs e)
    {
        var world = ObiColliderWorld.GetInstance();
        foreach (var contact in e.contacts)
        {
            // this one is an actual collision:
            if (contact.distance < 0.01)
            {
                var theCollider = world.colliderHandles[contact.other].owner;
                if (theCollider)
                {
                    print(theCollider.name);
                }
            }
        }
    }
}

Well, you're writing the collider name to console once per contact, no wonder performance goes down the drain  Huh. Writing to the console is extremely slow.
Remove the print() line and it should run acceptably fast.

Edit: also, you're using the second index of the contact (which for particle-particle contacts, is a particle index) to access the collider handles array, which will result in an out of bounds exception.
Reply


Messages In This Thread
Detect specific rope collision. - by flaurens - 05-10-2020, 08:45 AM
RE: Detect specific rope collision. - by flaurens - 05-10-2020, 12:18 PM
RE: Detect specific rope collision. - by Elegar - 09-11-2020, 09:53 PM
RE: Detect specific rope collision. - by Elegar - 11-11-2020, 12:16 PM
RE: Detect specific rope collision. - by josemendez - 19-11-2020, 02:25 PM
RE: Detect specific rope collision. - by Gauri7 - 04-07-2022, 11:57 AM
RE: Detect specific rope collision. - by Gauri7 - 04-07-2022, 02:12 PM
RE: Detect specific rope collision. - by Gauri7 - 05-07-2022, 09:33 AM
RE: Detect specific rope collision. - by Gauri7 - 06-07-2022, 12:20 PM
RE: Detect specific rope collision. - by Gauri7 - 08-07-2022, 09:35 AM