}//OnStateEnter public override bool Action() { base.Action(); if (Time.timeSinceLevelLoad - this.enteredTime < 1f) { AICtrl.MvmntCmp.SetVelocity(Vector2.zero); return false; } if (bIsAtTarget) return false; if (this.target == null) { this.target = _wpCtrl.GetNext().transform; } bool hasArrived = this.GoToTarget(this.target); if (hasArrived) { bIsAtTarget = _wpCtrl.IsAtLastPoint(); this.target = _wpCtrl.GetNext().transform; } if (bIsAtTarget) { _wpCtrl.ResetPatrolPoints(); AICtrl.OnLookAround(this.BackToPatrol); } return true; }//Action
}//Action protected override void OnLastPointReached(WaypointControl wpCtrl) { base.OnLastPointReached(wpCtrl); if (wpCtrl.IsWaitingAtWaypoint) { this.deferPointSwitch = true; return; } wpCtrl.FlipIterationIndex(); if (!bUsePatrolPath) { var t = wpCtrl.GetActivePoint(); wpCtrl.ResetPatrolPoints(); bUsePatrolPath = true; this.target = wpCtrl.GetNext(t).transform; } }//OnLastPointReached
}//Action public virtual bool GoToTarget(Transform target) { if (this.target == null) return false; BoxCollider2D box = AICtrl.ControlledBy.ColliderCmp as BoxCollider2D; Vector2 size = box.size; float direction = AICtrl.DirSwitcherCmp.Direction; Vector2 distanceVector = (target.position - AICtrl.transform.position); float distance = Vector2.Distance(AICtrl.transform.position, target.position); //Vector2 deltaMovement = Vector2.right * AICtrl.MvmntCmp.RunSpeed * direction; //Vector3 deltaMovement = AICtrl.MvmntCmp.Velocity; //if (deltaMovement.x > distance) { // deltaMovement.x = distance; //} //_input.SetHorizontalAxis(Mathf.Sign(distanceVector.x)); //if (!AICtrl.IsLookingAtTarget(target) && // Mathf.Abs(distanceVector.x) >= (size.x / 2) && // !AICtrl.LadderClimberCmp.IsClimbing) { // //AICtrl.DirSwitcherCmp.OnSwitchDirection(); // //direction = AICtrl.DirSwitcherCmp.Direction; // _input.SetHorizontalAxis(_input.GetHorizontalAxis() * -1); //} Vector2 inputValue = Vector2.zero; inputValue.x = Mathf.Sign(distanceVector.x); bool isAtX = Mathf.Abs(distanceVector.x) <= size.x / 2; bool isAtY = false; if (distanceVector.y <= 0 && !AICtrl.LadderClimberCmp.IsClimbing) { isAtY = Mathf.Abs(distanceVector.y) <= size.y / 2; } else if (distanceVector.y <= 0 && AICtrl.LadderClimberCmp.IsClimbing) { if (Mathf.Abs(distanceVector.y) <= size.y / 2) isAtY = AICtrl.ControlledBy.IsGrounded; } //if (!isAtX) // deltaMovement.x = AICtrl.MvmntCmp.RunSpeed * direction; //else // deltaMovement.x = 0; ////FIXME: this shouldn't be here. Should be called first by Actor, ////but it doesn't (or it is too late). //AICtrl.ControlledBy.CollisionDetector.Move(ref deltaMovement); if (isAtX && !isAtY) { if (climbDir == 0) climbDir = Mathf.Sign(distanceVector.normalized.y); //if (AICtrl.LadderClimberCmp.IsOnLadder) { // UseLadder(ref deltaMovement, climbDir); //} //_input.SetVerticalAxis(climbDir); inputValue.y = climbDir; inputValue.x = 0f; } if (isAtY) { //_input.SetVerticalAxis(0); climbDir = 0f; inputValue.y = climbDir; } if(AICtrl.LadderClimberCmp.IsClimbing) inputValue.x = 0f; ////if (AICtrl.LadderClimberCmp.IsClimbing) //// isAtY = false; ////else //// climbDir = 0f; //AICtrl.MvmntCmp.SetVelocity(deltaMovement); bool hasArrived = isAtX && isAtY; if (hasArrived) { this.target = _wpCtrl.GetNext().transform; inputValue.x = 0; } _input.SetHorizontalAxis(inputValue.x); _input.SetVerticalAxis(inputValue.y); return hasArrived; }//GoToTarget