Пример #1
0
    /// <summary>
    /// Assists position. In other words,
    /// Find the closest target to be hit & moves to a position to better ensure hit.
    /// </summary>
    /// <param name="seconds">Seconds.</param>
    protected void assistPosition(float seconds)
    {
        //how close does an enemy need to be for this to be activated
        float positionValidDistance = 3f;
        //move position that is this far from the target
        float distanceFromTarget = 2f;
        PlayerCombatHandler pch  = _weapon.GetOwner() as PlayerCombatHandler;

        //find close enemy
        //		if (EnemyAIHandler.EnemyList.Count > 0) {
        if (CombatHandler.GET_ENEMIES(pch.GetTeam(), true).Count > 0)
        {
            Transform ownerTransform = _weapon.GetOwner().transform;
            Vector3   camForward     = Vector3.Scale(CameraController.CC.CombatCamera.transform.forward, new Vector3(1, 0, 1)).normalized;
            Vector3   searchPos      = ownerTransform.position + camForward;

            //if an enemy is close to valid distance, assist position
//			if (EnemyAIHandler.GetClosestEnemyDistance (searchPos) < positionValidDistance) {
            if (pch.GetClosestEnemyDistance(searchPos) < positionValidDistance)
            {
                CombatHandler closestEnemy = pch.GetClosestEnemy(searchPos);
                //direction from target to this character
                Vector3 direction = ownerTransform.position - closestEnemy.transform.position;
                direction = new Vector3(direction.x, 0f, direction.z);
                direction = direction.normalized * distanceFromTarget;

                //position a certain distance(distanceFromTarget) from the target
                direction = closestEnemy.transform.position + direction;

                //move towards that position
                StartCoroutine(MathHelper.IELerpRBPositionOverTime(ownerTransform.GetComponent <Rigidbody> (), ownerTransform.position, direction, seconds));

//				//dev
//				GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
//				cube.transform.position = direction;
//				Debug.Break ();
//				Quaternion toRotation = Quaternion.LookRotation (direction);
//				StartCoroutine (MathHelper.IELerpRotationOverTime (ownerTransform, ownerTransform.rotation, toRotation, seconds));
            }
        }
    }
Пример #2
0
    /// <summary>
    /// Assists aim. In other words,
    /// Find the closest target to be hit & aims towards the target automatically.
    /// </summary>
    /// <param name="seconds">How fast does this character aim</param>
    protected void assistAim(float seconds)
    {
        float aimValidDistance  = 3f;
        PlayerCombatHandler pch = _weapon.GetOwner() as PlayerCombatHandler;

//		_targetFound = false;
        //find close enemy
//		if (EnemyAIHandler.EnemyList.Count > 0) {
        if (CombatHandler.GET_ENEMIES(pch.GetTeam(), true).Count > 0)
        {
            Transform ownerTransform = _weapon.GetOwner().transform;
            Vector3   camForward     = Vector3.Scale(CameraController.CC.CombatCamera.transform.forward, new Vector3(1, 0, 1)).normalized;
            Vector3   searchPos      = ownerTransform.position + camForward;

            //if an enemy is close to valid distance, use aimAssist
            if (pch == null)
            {
                Debug.LogWarning("WARNING : Playercharacter must have PlayerCombatHandler");
            }
            else
            {
                if (pch.GetClosestEnemyDistance(searchPos) < aimValidDistance)
                {
                    CombatHandler closestEnemy = pch.GetClosestEnemy(searchPos);
//					EnemyAIHandler closeEnemey = EnemyAIHandler.GetClosestEnemy (searchPos);
//				_targetPos = closeEnemey.transform.position;
                    Vector3 direction = closestEnemy.transform.position - ownerTransform.position;
                    direction = new Vector3(direction.x, 0f, direction.z);
                    Quaternion toRotation = Quaternion.LookRotation(direction);
                    StartCoroutine(MathHelper.IELerpRotationOverTime(ownerTransform, ownerTransform.rotation, toRotation, seconds));
//				_targetFound = true;
                }
//			else {
//				print ("Not close enough, target : " + EnemyAIHandler.GetClosestEnemy (searchPos).name + ", distance : " + EnemyAIHandler.GetClosestEnemyDistance (searchPos));
//			}
            }
        }
    }