예제 #1
0
    /// <summary>
    /// Gets the current status of the protagonist
    /// </summary>
    /// <returns>Status object</returns>
    public Status GetStatus()
    {
        // Calculate whether the protagonist is currently physically
        // supported using a trigger collider overlap test
        var filter = new ContactFilter2D();

        filter.SetLayerMask(PhysicalSupportLayerMask);
        var results = new Collider2D[1];
        var number_of_physical_suports =
            PhysicalSupport.OverlapCollider(filter, results);

        return(new Status()
        {
            // If there is at least one physical support,
            // then the protagonist is physically supported
            IsPhysicallySupported = number_of_physical_suports > 0
        });
    }
예제 #2
0
    public Status GetStatus(PreStatus prestatus)
    {
        // Calculate whether the protagonist is currently physically
        // supported using a trigger collider overlap test
        var filter = new ContactFilter2D();

        filter.SetLayerMask(PhysicalSupportLayerMask);
        var results = new Collider2D[1];
        var number_of_physical_suports =
            PhysicalSupport.OverlapCollider(filter, results);

        Vector2 center_of_mass = new Vector2();
        float   mass           = 0;
        var     bodies         = new List <Rigidbody2D>
        {
            Rigidbody
        };

        if (prestatus.IsOnBoard)
        {
            bodies.Add(SkateboardJoint.connectedBody);
        }
        foreach (var rb in bodies)
        {
            center_of_mass += rb.worldCenterOfMass * rb.mass;
            mass           += rb.mass;
        }
        center_of_mass /= mass;

        return(new Status()
        {
            // If there is at least one physical support,
            // then the protagonist is physically supported
            IsPhysicallySupported = number_of_physical_suports > 0,
            CombinedCenterOfMass = center_of_mass,
            GrindReady = Rigidbody.velocity.y <= 0.01f,
        });
    }