void ObstacleRoutine(Vector3 diffxz, Vector3 destination) { List <Collider> obstacles = Physics.OverlapBox((transform.position) - (diffxz.normalized * obstaclesCheckExtend.z), obstaclesCheckExtend, transform.rotation, physicalLayer).ToList(); if (obstacles.Count > 0 && obstacles.Exists(col => col.gameObject.layer != agentLayer)) { bool didJump = false; if (Time.timeSinceLevelLoad - lastJumpTime > jumpCooldown && sensor.IsGrounded) // TODO: check if possible to jump over { Collider theObstacle = obstacles.First(col => col.gameObject.layer != agentLayer); float height = theObstacle.bounds.extents.y + theObstacle.bounds.center.y; float jumpforce = 280f * height; if (jumpforce < maxJumpForce) { actions.Jump(jumpforce); didJump = true; lastJumpTime = Time.timeSinceLevelLoad; } } if (!didJump && sensor.IsGrounded) { SetDestination(destination); } // else if you can shoot through, do so } }
// Update is called once per frame void FixedUpdate() { // ALL of this is debug // TODO: remove if (doMoveTowards) { actionSet.MoveTowards(target.position, moveSpeed); } if (doJump) { actionSet.Jump(jumpHeight); doJump = false; } if (doPickupRight) { Physics.IgnoreCollision(GetComponent <CapsuleCollider>(), rightPickupTarget.GetComponent <Collider>()); actionSet.PickupObject(rightPickupTarget, rightHand, rightHand.Find("WeaponPos")); doPickupRight = false; } if (doPickupLeft) { Physics.IgnoreCollision(GetComponent <CapsuleCollider>(), leftPickupTarget.GetComponent <Collider>()); actionSet.PickupObject(leftPickupTarget, leftHand, leftHand.Find("WeaponPos")); doPickupLeft = false; } /*if (doDrop) * { * Vector3 velocity = hand.GetComponent<Rigidbody>().velocity; * actionSet.DropObject(pickupTarget, hand.transform, velocity); * doDrop = false; * }*/ if (doActivateRight) { actionSet.ActivateObject(rightPickupTarget, rightHand.Find("WeaponPos")); } if (doActivateLeft) { actionSet.ActivateObject(leftPickupTarget, leftHand.Find("WeaponPos")); } if (doAimAtRight) { rightSlerpPos += 0.2f; actionSet.AimAt(rightHand, target.position, rightSlerpPos); if (rightSlerpPos > 1) { rightSlerpPos = 0; } //doAimAtRight = false; } if (doAimAtLeft) { leftSlerpPos += 0.2f; actionSet.AimAt(leftHand, target.position, leftSlerpPos); if (leftSlerpPos > 1) { leftSlerpPos = 0; } } if (doCrouch) { actionSet.Crouch(leg, originalHeight, 0.3f); doCrouch = false; } if (doStandup) { actionSet.StandUp(leg, originalHeight); doStandup = false; } if (doReload) { actionSet.ReloadWeapon(rightPickupTarget); actionSet.ReloadWeapon(leftPickupTarget); doReload = false; } if (doOrientate) { actionSet.TurnTowards(target, 1.0f, 2.0f, 7f); } if (setDestinationWithStrafe) { setDestinationWithoutStrafe = false; setDestinationWithStrafe = activitySet.GoTowardsDestination(destination.position); actionSet.TurnTowards(destination, 1.0f, 2.0f, 7f); } if (setDestinationWithoutStrafe) { setDestinationWithStrafe = false; setDestinationWithoutStrafe = activitySet.GoTowardsDestination(destination.position, false); //actionSet.TurnTowards(destination, 1.0f, 2.0f, 7f); } //animator.SetInteger("RoutineStatus", routineStatus); }