예제 #1
0
    private void drawPushPullDirections(push_type type)
    {
        Vector3 origin      = gameObject.transform.position;
        float   heading     = (angle_offset / 180) * Mathf.PI;
        float   line_length = 5.0f;

        Gizmos.color = Color.red;
        switch (type)
        {
        case push_type.Free:
            Vector3 end = new Vector3(0.0f, line_length, 0.0f);
            Gizmos.DrawLine(origin, origin + end);
            break;

        case push_type.TwoAxis:
            for (int i = 0; i < 2; i++)
            {
                Gizmos.DrawLine(origin, origin + new Vector3(Mathf.Sin(heading + (Mathf.PI) * i) * line_length, 0.0f, Mathf.Cos(heading + (Mathf.PI) * i) * line_length));
            }
            break;

        case push_type.FourAxis:
            for (int i = 0; i < 4; i++)
            {
                Gizmos.DrawLine(origin, origin + new Vector3(Mathf.Sin(heading + (Mathf.PI / 2) * i) * line_length, 0.0f, Mathf.Cos(heading + (Mathf.PI / 2) * i) * line_length));
            }
            break;

        case push_type.HeightAxis:;
            for (int i = 0; i < 8; i++)
            {
                Gizmos.DrawLine(origin, origin + new Vector3(Mathf.Sin(heading + (Mathf.PI / 4) * i) * line_length, 0.0f, Mathf.Cos(heading + (Mathf.PI / 4) * i) * line_length));
            }
            break;
        }
    }
예제 #2
0
 private void drawPushPullDirections(push_type type)
 {
     Vector3 origin = gameObject.transform.position;
     float heading = (angle_offset / 180) * Mathf.PI;
     float line_length = 5.0f;
     Gizmos.color = Color.red;
     switch (type) {
     case push_type.Free:
         Vector3 end = new Vector3(0.0f, line_length, 0.0f);
         Gizmos.DrawLine(origin, origin + end);
         break;
     case push_type.TwoAxis:
         for(int i = 0; i < 2; i++){
             Gizmos.DrawLine(origin, origin + new Vector3(Mathf.Sin(heading + (Mathf.PI) * i)* line_length, 0.0f, Mathf.Cos(heading + (Mathf.PI) * i) * line_length));
         }
         break;
     case push_type.FourAxis:
         for(int i = 0; i < 4; i++){
             Gizmos.DrawLine(origin, origin + new Vector3(Mathf.Sin(heading + (Mathf.PI/2) * i)* line_length, 0.0f, Mathf.Cos(heading + (Mathf.PI/2) * i) * line_length));
         }
         break;
     case push_type.HeightAxis:;
         for(int i = 0; i < 8; i++){
             Gizmos.DrawLine(origin, origin + new Vector3(Mathf.Sin(heading + (Mathf.PI/4) * i)* line_length, 0.0f, Mathf.Cos(heading + (Mathf.PI/4) * i) * line_length));
         }
         break;
     }
 }
예제 #3
0
    private void crate_pushPull(Vector3 player_pos, float magnitude, push_type type, float push_range, bool pull)
    {
        Vector3 heading = new Vector3(0.0f, 0.0f, 0.0f);
        float   angle   = 0.0f;
        float   offset  = (angle_offset / 180) * Mathf.PI;
        Vector3 pos     = Vector3.zero;

        // Checks for range of quinc.
        if (Vector3.Distance(player_pos, gameObject.transform.position) >= push_range)
        {
            return;
        }

        switch (type)
        {
        case push_type.Free:
            heading = gameObject.transform.position - player_pos;
            break;

        case push_type.TwoAxis:
            heading = gameObject.transform.position - player_pos;
            angle   = Vector3.Angle(heading, Vector3.Normalize(Vector3.forward + new Vector3(Mathf.Sin(offset), 0.0f, Mathf.Cos(offset))));
            if (angle > 0.0f && angle <= 90.0f)
            {
                heading = new Vector3(Mathf.Sin(offset), 0.0f, Mathf.Cos(offset));
            }
            else if (angle > 90.0f && angle <= 180.0f)
            {
                heading = new Vector3(Mathf.Sin(offset + Mathf.PI), 0.0f, Mathf.Cos(offset + Mathf.PI));
            }
            else
            {
                heading = Vector3.zero;
            }
            break;

        case push_type.FourAxis:
            heading = gameObject.transform.position - player_pos;
            pos     = gameObject.transform.position;
            angle   = Vector3.Angle(heading, Vector3.Normalize(Vector3.forward + new Vector3(Mathf.Sin(offset), 0.0f, Mathf.Cos(offset))));
            if (angle > 0.0f && angle <= 45.0f)
            {
                heading = new Vector3(Mathf.Sin(offset), 0.0f, Mathf.Cos(offset));
            }
            else if (angle > 135.0f && angle <= 180.0f)
            {
                heading = new Vector3(Mathf.Sin(offset + Mathf.PI), 0.0f, Mathf.Cos(offset + Mathf.PI));
            }
            else if (angle > 45.0f && angle <= 135.0f && pos.x > player_pos.x)
            {
                heading = new Vector3(Mathf.Sin(offset + Mathf.PI / 2), 0.0f, Mathf.Cos(offset + Mathf.PI / 2));
            }
            else if (angle > 45.0f && angle <= 135.0f && pos.x < player_pos.x)
            {
                heading = new Vector3(Mathf.Sin(offset + (3 * Mathf.PI / 2)), 0.0f, Mathf.Cos(offset + (3 * Mathf.PI / 2)));
            }
            break;

        case push_type.HeightAxis:
            heading = gameObject.transform.position - player_pos;
            pos     = gameObject.transform.position;
            angle   = Vector3.Angle(heading, Vector3.Normalize(Vector3.forward + new Vector3(Mathf.Sin(offset), 0.0f, Mathf.Cos(offset))));
            if (angle > 0.0f && angle <= 22.5f)
            {
                heading = Vector3.forward;
            }
            else if (angle > 22.5f && angle <= 45.0f && pos.x > player_pos.x)
            {
                heading = new Vector3(Mathf.Sin(Mathf.PI / 4), 0.0f, Mathf.Cos(Mathf.PI / 4));
            }
            else if (angle > 22.5f && angle <= 45.0f && pos.x < player_pos.x)
            {
                heading = new Vector3(-Mathf.Sin(Mathf.PI / 4), 0.0f, Mathf.Cos(Mathf.PI / 4));
            }
            else if (angle > 45.0f && angle <= 135.0f && pos.x > player_pos.x)
            {
                heading = Vector3.right;
            }
            else if (angle > 45.0f && angle <= 135.0f && pos.x < player_pos.x)
            {
                heading = Vector3.left;
            }
            else if (angle > 135.0f && angle <= 157.5f && pos.x > player_pos.x)
            {
                heading = new Vector3(Mathf.Sin(Mathf.PI / 4), 0.0f, -Mathf.Cos(Mathf.PI / 4));
            }
            else if (angle > 135.0f && angle <= 157.5f && pos.x < player_pos.x)
            {
                heading = new Vector3(-Mathf.Sin(Mathf.PI / 4), 0.0f, -Mathf.Cos(Mathf.PI / 4));
            }
            else if (angle > 135.0f && angle <= 180.0f)
            {
                heading = Vector3.back;
            }
            else
            {
                heading = Vector3.zero;
            }
            break;

        case push_type.Anim:
            if (gameObject.transform.parent.gameObject.GetComponent <ItemAnimator>())
            {
                gameObject.transform.parent.gameObject.GetComponent <ItemAnimator>().set_in_motion();
            }
            return;
        }

        heading.y = 0.0f;
        float   distance  = heading.magnitude;
        Vector3 direction = heading / distance;

        if (pull)
        {
            direction *= -1;
        }

        Rigidbody rb = gameObject.GetComponent <Rigidbody> ();

        rb.AddForce(direction * (magnitude * 100));
    }
예제 #4
0
    private void crate_pushPull(Vector3 player_pos, float magnitude, push_type type, float push_range, bool pull)
    {
        Vector3 heading = new Vector3(0.0f, 0.0f, 0.0f);
        float angle = 0.0f;
        float offset = (angle_offset / 180) * Mathf.PI;
        Vector3 pos = Vector3.zero;

        // Checks for range of quinc.
        if (Vector3.Distance (player_pos, gameObject.transform.position) >= push_range) {
            return;
        }

        switch (type) {
        case push_type.Free:
            heading = gameObject.transform.position - player_pos;
            break;
        case push_type.TwoAxis:
            heading = gameObject.transform.position - player_pos;
            angle = Vector3.Angle(heading, Vector3.Normalize(Vector3.forward + new Vector3(Mathf.Sin(offset), 0.0f, Mathf.Cos(offset))));
            if(angle > 0.0f && angle <= 90.0f) heading = new Vector3(Mathf.Sin(offset), 0.0f, Mathf.Cos(offset));
            else if(angle > 90.0f && angle <= 180.0f) heading = new Vector3(Mathf.Sin(offset + Mathf.PI), 0.0f, Mathf.Cos(offset + Mathf.PI));
            else heading = Vector3.zero;
            break;
        case push_type.FourAxis:
            heading = gameObject.transform.position - player_pos;
            pos = gameObject.transform.position;
            angle = Vector3.Angle(heading, Vector3.Normalize(Vector3.forward + new Vector3(Mathf.Sin(offset), 0.0f, Mathf.Cos(offset))));
            if(angle > 0.0f && angle <= 45.0f) heading = new Vector3(Mathf.Sin(offset), 0.0f, Mathf.Cos(offset));
            else if(angle > 135.0f && angle <= 180.0f) heading = new Vector3(Mathf.Sin(offset + Mathf.PI), 0.0f, Mathf.Cos(offset + Mathf.PI));
            else if(angle > 45.0f && angle <= 135.0f && pos.x > player_pos.x) heading = new Vector3(Mathf.Sin(offset + Mathf.PI/2), 0.0f, Mathf.Cos(offset + Mathf.PI/2));
            else if(angle > 45.0f && angle <= 135.0f && pos.x < player_pos.x) heading = new Vector3(Mathf.Sin(offset + (3*Mathf.PI/2)), 0.0f, Mathf.Cos(offset + (3*Mathf.PI/2)));
            break;
        case push_type.HeightAxis:
            heading = gameObject.transform.position - player_pos;
            pos = gameObject.transform.position;
            angle = Vector3.Angle(heading, Vector3.Normalize(Vector3.forward + new Vector3(Mathf.Sin(offset), 0.0f, Mathf.Cos(offset))));
            if(angle > 0.0f && angle <= 22.5f) heading = Vector3.forward;
            else if(angle > 22.5f && angle <= 45.0f && pos.x > player_pos.x) heading = new Vector3(Mathf.Sin(Mathf.PI / 4), 0.0f, Mathf.Cos(Mathf.PI / 4));
            else if(angle > 22.5f && angle <= 45.0f && pos.x < player_pos.x) heading = new Vector3(-Mathf.Sin(Mathf.PI / 4), 0.0f, Mathf.Cos(Mathf.PI / 4));
            else if(angle > 45.0f && angle <= 135.0f && pos.x > player_pos.x) heading = Vector3.right;
            else if(angle > 45.0f && angle <= 135.0f && pos.x < player_pos.x) heading = Vector3.left;
            else if(angle > 135.0f && angle <= 157.5f && pos.x > player_pos.x) heading = new Vector3(Mathf.Sin(Mathf.PI / 4), 0.0f, -Mathf.Cos(Mathf.PI / 4));
            else if(angle > 135.0f && angle <= 157.5f && pos.x < player_pos.x) heading = new Vector3(-Mathf.Sin(Mathf.PI / 4), 0.0f, -Mathf.Cos(Mathf.PI / 4));
            else if(angle > 135.0f && angle <= 180.0f) heading = Vector3.back;
            else heading = Vector3.zero;
            break;
        case push_type.Anim:
            if (gameObject.transform.parent.gameObject.GetComponent<ItemAnimator>())
            {
                gameObject.transform.parent.gameObject.GetComponent<ItemAnimator>().set_in_motion();
            }
            return;
        }

        heading.y = 0.0f;
        float distance = heading.magnitude;
        Vector3 direction = heading / distance;

        if (pull) direction *= -1;

        Rigidbody rb = gameObject.GetComponent<Rigidbody> ();
        rb.AddForce(direction * (magnitude * 100));
    }