コード例 #1
0
ファイル: HeroController.cs プロジェクト: RicoP/solidarity
    private static void MakeTouchable(Ladder ladder, bool touchable)
    {
        var laddercollider = ladder.GetComponent <Collider>();

        laddercollider.isTrigger = !touchable;

        var ladderbody = ladder.GetComponent <Rigidbody>();

        ladderbody.isKinematic = !touchable;
    }
コード例 #2
0
    private void Update()
    {
        SpriteRenderer sr     = ladder.GetComponent <SpriteRenderer>();
        BoxCollider2D  bc2d   = GetComponent <BoxCollider2D>();
        float          height = sr.size.y;

        switch (ladderPart)
        {
        case Part.TOP:
            //transform.position = new Vector2(transform.position.x,
            //ladder.transform.position.y+height/2+bc2d.size.y/2);
            transform.position = new Vector2(transform.position.x,
                                             ladder.transform.position.y + height + bc2d.size.y / 2);
            break;

        case Part.BUTTOM:
            // transform.position = new Vector2(transform.position.x,
            // ladder.transform.position.y-height/2+bc2d.size.y/2);
            transform.position = new Vector2(transform.position.x,
                                             ladder.transform.position.y + bc2d.size.y / 2);
            break;

        default:
            break;
        }
    }
コード例 #3
0
    private bool IsPlayerOnLadderBottom()
    {
        if (ladder == null)
        {
            return(false);
        }

        BoxCollider2D ladderBc2d;

        ladderBc2d = ladder.GetComponent <BoxCollider2D> ();

        float ladderBottom = ladderBc2d.bounds.center.y - ladderBc2d.bounds.extents.y;

        float playerBottom = bc2d.bounds.center.y - bc2d.bounds.extents.y;

        if ((playerBottom - ladderBottom) < deltaLadderBoundaries)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
コード例 #4
0
ファイル: HeroController.cs プロジェクト: RicoP/solidarity
    void Update()
    {
        Ray        ray = new Ray(halterCamera.transform.position, halterCamera.transform.forward);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, float.PositiveInfinity, groundLayer))
        {
            var dirx   = Input.GetAxis(AxisHorz);
            var diry   = Input.GetAxis(AxisVert);
            var action = Input.GetButtonDown(BtnAction);

            Debug.DrawRay(hit.point, hit.normal * 2, Color.blue);
            var upVector = Vector3.Cross(halterCamera.transform.right, hit.normal);
            Debug.DrawRay(hit.point, upVector * 2, Color.green);
            var rightVector = Vector3.Cross(-halterCamera.transform.forward, hit.normal);
            Debug.DrawRay(hit.point, rightVector * 2, Color.red);

            if (action)
            {
                Debug.Log("action!");
                ExecuteAction();
            }

            if (snappedToLadder == null)
            {
                Vector3 direction = upVector * diry + rightVector * dirx;
                direction  *= speed;
                direction.y = rigidbody.velocity.y; //keep gravity

                rigidbody.velocity = direction;

                SetBool("walking", rigidbody.velocity.magnitude > 0.1f);

                if (Mathf.Abs(rigidbody.velocity.x) > 0.5f && kind == Kind.Holder)
                {
                    PlayFootstepSound();
                }
            }
            else
            {
                if (touchNotifier.ladders.Contains(snappedToLadder))
                {
                    if (snappedToLadder.Standing)
                    {
                        Vector3 direction = snappedToLadder.Up * diry;
                        direction         *= ladderClimpSpeed;
                        rigidbody.velocity = direction + snappedToLadder.GetComponent <Rigidbody>().velocity;
                        if (otherhero.holdingObject && otherhero.holdingObject.Is <Ladder>())
                        {
                            rigidbody.velocity += otherhero.rigidbody.velocity;
                        }

                        if (Mathf.Abs(rigidbody.velocity.y) > 0.1f)
                        {
                            PlayFootstepLeiterSound();
                        }

                        Debug.Log(transform.position.y);
                        if (transform.position.y <= 2.1 && diry < 0)
                        {
                            UnsnapFromLadder();
                        }
                    }
                    else
                    {
                        UnsnapFromLadder();
                    }
                }
                else
                {
                    UnsnapFromLadder();
                }
            }
        }
    }