public IEnumerator PickupKickObject(KickObject obj)
    {
        // turn off the rigidbody and collider.
        obj.rb.isKinematic = true;
        obj.coll.enabled   = false;
        obj.rb.velocity    = Vector2.zero;
        obj.spriteRenderer.sortingOrder += 100;

        float   startTime  = Time.time;
        Vector3 start      = obj.transform.position;
        Color   startColor = obj.spriteRenderer.color;
        Color   endColor   = obj.spriteRenderer.color;

        endColor.a = 0f;
        while (Time.time - startTime < pickupTweenTime)
        {
            float t = (Time.time - startTime) / pickupTweenTime;
            obj.transform.position   = Vector3.Lerp(start, kickTarget.position, t);
            obj.spriteRenderer.color = Color.Lerp(startColor, endColor, t);
            yield return(null);
        }
        obj.transform.position = kickTarget.position;
        obj.inPlace            = true;
        obj.gameObject.SetActive(false);
    }
Пример #2
0
    void PickupObject()
    {
        Vector2 castOrigin    = new Vector2(transform.position.x, transform.position.y) + coll.offset;
        Vector2 castDirection = facingDirection;
        int     layerMask     = ~LayerMask.GetMask("Player");

        //Vector2 origin, float radius, Vector2 direction, float distance = Mathf.Infinity, int layerMask = DefaultRaycastLayers
        RaycastHit2D hit = Physics2D.CircleCast(castOrigin, coll.radius, facingDirection, GRAB_RANGE, layerMask);//Physics2D.Raycast(castOrigin, castDirection, GRAB_RANGE, layerMask);

        //Debug.DrawRay(castOrigin, castDirection, Color.blue, 2f);

        if (hit && hit.collider != null)
        {
            //Debug.Log("hit " + hit + " hit.collider " + hit.collider.gameObject.name);
        }
        if (hit && hit.collider.gameObject.CompareTag("Kick") && !hit.collider.isTrigger)
        {
            held = hit.collider.GetComponent <KickObject>();
            originalHeldParent = held.transform.parent;
            held.transform.SetParent(transform);
            held.rb.velocity    = Vector2.zero;
            held.rb.isKinematic = true;
            held.coll.enabled   = false;
            held.spriteRenderer.sortingOrder += 1;
        }
    }
Пример #3
0
 void DropObject()
 {
     if (held != null)
     {
         held.transform.SetParent(originalHeldParent);
         held.rb.isKinematic = false;
         held.rb.velocity    = Vector2.zero;
         held.coll.enabled   = true;
         held.spriteRenderer.sortingOrder -= 1;
     }
     held = null;
     originalHeldParent = null;
 }