Esempio n. 1
0
    private void CheckGrab()
    {
        Vector3 rayStart = player.position + (player.forward * player.GetComponent <Collider>().bounds.extents.z);

        RaycastHit hit;

        if (Physics.Raycast(rayStart, player.forward, out hit, GrabDistance, GrabCollision))
        {
            target    = hit.transform;
            isInRange = true;

            // check that player can grab object face
            PushDirection pushDir = GetPushDirection();

            if (pushDir == PushDirection.TargetForward && playerInteraction.canGrabBack)
            {
                return;
            }
            else if (pushDir == PushDirection.TargetBack && playerInteraction.canGrabFront)
            {
                return;
            }
            else if (pushDir == PushDirection.TargetRight && playerInteraction.canGrabLeft)
            {
                return;
            }
            else if (pushDir == PushDirection.TargetLeft && playerInteraction.canGrabRight)
            {
                return;
            }
        }

        target    = null;
        isInRange = false;
    }
Esempio n. 2
0
        //Pushes the creature, alters the velocity
        public void Push(PushDirection direction, float power)
        {
            switch (direction)
            {
            //Back
            case PushDirection.Middle:
                if (this.Velocity < 0.05)
                {
                    this.Velocity += power;
                }
                break;

            //Left
            case PushDirection.TurnLeft:
                if (this.TurningVelocity > -0.1e-6)
                {
                    this.TurningVelocity -= power;
                }
                break;

            //Right
            case PushDirection.TurnRight:
                if (this.TurningVelocity < 0.1e-6)
                {
                    this.TurningVelocity += power;
                }
                break;
            }
        }
Esempio n. 3
0
 public void Orphanize()
 {
     this.transform.parent = null;
     attached = false;
     parent = ParentedObj.None;
     pushDir = PushDirection.None;
     parentTransform = null;
 }
Esempio n. 4
0
 //If no longer pushing a car
 private void OnTriggerExit(Collider other)
 {
     if (other.tag == "Player" && other.gameObject.GetComponent <Rigidbody>() != null)
     {
         currentDirection = PushDirection.None;
         otherPlayer.GetComponent <Rigidbody>().drag = 0f;
         transform.rotation = Quaternion.Slerp(transform.rotation, startingRotation, .2f);
     }
 }
Esempio n. 5
0
    //Determine which way to push the other car
    private void DetermineWhatSideToPushBack(Collider other)
    {
        float zDistance = Math.Abs(transform.position.z) - Math.Abs(other.transform.position.z);
        float xDistance = Math.Abs(transform.position.x) - Math.Abs(other.transform.position.x);

        otherPlayer = other.gameObject;
        if (zDistance > 0)
        {
            currentDirection = PushDirection.Right;
        }
        else if (zDistance < 0)
        {
            currentDirection = PushDirection.Left;
        }
        if (xDistance > 0)
        {
            currentDirection = PushDirection.Front;
        }
    }
Esempio n. 6
0
    public void Push(float power, PushDirection dir)
    {
        switch (dir)
        {
        case PushDirection.Up:
            velocity.y += power;
            break;

        case PushDirection.Down:
            velocity.y -= power;
            break;

        case PushDirection.Left:
            velocity.x -= power;
            break;

        case PushDirection.Right:
            velocity.x += power;
            break;
        }
    }
Esempio n. 7
0
    public void Push(float force, PushDirection direction)
    {
        if (!ragdollOn)
        {
            FallDown();
            switch (direction)
            {
            case PushDirection.BACK:
                AddForce(force * -velBody.GetForward());
                break;

            case PushDirection.DOWN:
                AddForce(force * Vector3.down);
                break;

            case PushDirection.BACK_DOWN:
                AddForce(force * (-velBody.GetForward() + Vector3.down).normalized);
                break;
            }
            StopCoroutine(WaitAndGetUp());
            StartCoroutine(WaitAndGetUp());
        }
    }
Esempio n. 8
0
    void Move()
    {
        switch (_pushDirection)
        {
        case PushDirection.Right:
            _boxCollider.enabled = true;
            if (_curPosition.transform.position.x > end_x)
            {
                speed         *= -1;
                _pushDirection = PushDirection.Left;
            }
            break;

        case PushDirection.Left:
            _boxCollider.enabled = false;
            if (_curPosition.transform.position.x < start_x)
            {
                speed         *= -1;
                _pushDirection = PushDirection.Right;
            }
            break;
        }
        gameObject.transform.Translate(speed * Time.deltaTime, 0f, 0f);
    }
Esempio n. 9
0
    private IEnumerator Grab()
    {
        // Disable player movement
        playerMotor.canControl = false;

        // get push direction
        playerPushDir = GetPushDirection();

        // populate collider bounding points dictionary
        dicColliderPoints = GetColliderVertexPositions(target);

        Vector3 startPos = player.position;
        Vector3 endPos   = Vector3.zero;
        Vector3 temp     = Vector3.zero;

        float zExtents = (dicColliderPoints[ColliderBoundsVertex.LowerForwardLeft] - dicColliderPoints[ColliderBoundsVertex.LowerBackLeft]).magnitude / 2;
        float xExtents = (dicColliderPoints[ColliderBoundsVertex.LowerBackRight] - dicColliderPoints[ColliderBoundsVertex.LowerBackLeft]).magnitude / 2;

        if (playerPushDir == PushDirection.TargetForward)
        {
            temp = target.position - (target.forward * (zExtents + (playerCtrl.radius / 2) + GrabDistance));
        }
        else if (playerPushDir == PushDirection.TargetBack)
        {
            temp = target.position + (target.forward * (zExtents + (playerCtrl.radius / 2) + GrabDistance));
        }
        else if (playerPushDir == PushDirection.TargetRight)
        {
            temp = target.position - (target.right * (xExtents + (playerCtrl.radius / 2) + GrabDistance));
        }
        else if (playerPushDir == PushDirection.TargetLeft)
        {
            temp = target.position + (target.right * (xExtents + (playerCtrl.radius / 2) + GrabDistance));
        }

        endPos = new Vector3(temp.x, player.position.y, temp.z);

        // move player
        float startTime = Time.time;

        playerPushState = PushState.MovingPlayer;
        while (Time.time < startTime + GrabMoveTime)
        {
            Vector3 lastPos = player.position;
            Vector3 newPos  = Vector3.Lerp(startPos, endPos, (Time.time - startTime) / GrabMoveTime) - lastPos;

            playerCtrl.Move(newPos);
            yield return(null);
        }

        // set state
        playerPushState    = PushState.None;
        localGrabPosition  = target.position - player.position;
        targetLastPosition = target.position;
        targetLastRotation = target.eulerAngles;

        // smooth movement
        target.GetComponent <Rigidbody>().isKinematic = true;

        // set override push/pull parameters
        PushPullObject ppObj = target.GetComponent <PushPullObject>();

        if (ppObj != null)
        {
            overrideParameters = ppObj.parameters;
        }

        // Slow player movement
        SlowSpeed();
    }
Esempio n. 10
0
 void Start()
 {
     _boxCollider   = GetComponentInChildren <BoxCollider>();
     _curPosition   = GetComponent <Transform>();
     _pushDirection = PushDirection.Right;
 }
Esempio n. 11
0
    void ParentToHitTarget(Transform hit, PushDirection pushdirec)
    {
        if (hit.transform != null) {
            if (hit.transform.tag == "Tree") {
                if (Vector3.Distance(Vector3.Normalize(transform.position - hit.transform.parent.transform.position), hit.transform.parent.up) < 0.1f) {

                    if (hit.transform.parent.GetComponent<PillarController>().grow && !hit.transform.parent.GetComponent<PillarController>().atMaxHeight) {
                        this.transform.parent = hit.transform.parent.transform.GetChild(0);
                        parent = ParentedObj.Pillar;
                        parentTransform = this.transform.parent;
                        attached = true;
                        pushDir = pushdirec;
                    }

                }

            } else if (hit.transform.tag == "Kid") {
        //				Debug.Log (hit.transform.name);
        //				if (hit.transform.GetComponent<CharController6>().channel == 0) {

                    //if (hit.transform.GetComponent<CharController6>().nextNode == node) {
        //					if (Vector3.Angle(hit.transform.forward, new Vector3(transform.position.x, 0f, transform.position.z) - new Vector3(hit.transform.position.x, 0f, hit.transform.position.z)) < 2.5f) {

                        this.transform.parent = hit.transform.GetChild(1);
                        parent = ParentedObj.Kid;
                        parentTransform = this.transform.parent;
                        attached = true;
                        pushDir = pushdirec;
        //					}

        //				}

            }
        }
    }