示例#1
0
 void OnControllerColliderHit(ControllerColliderHit hit)
 {
     if (hit.collider.tag == "Player")
     {
         Vector3 pushDir = hit.transform.position - transform.position;
         pushDir  *= pushSpeed;
         pushDir.y = 10.5f;
         // This should allow us to interact with this script directly and define an appropriate behaviour that way
         MinifigControllerWTH hitCharacterController = hit.collider.GetComponentInParent <MinifigControllerWTH>();
         hitCharacterController.AddForce(pushDir);
     }
     if (hit.collider.tag == "floor")
     {
         Respawn();
     }
     if (hit.collider.tag == "Credit")
     {
         GameObject credit = hit.gameObject;
         AddPoints(1);
         Destroy(credit);
     }
     if (controller.isGrounded)
     {
         RaycastHit raycastHit;
         if (Physics.SphereCast(transform.position + Vector3.up * 0.8f, 0.8f, Vector3.down, out raycastHit, 0.1f, -1, QueryTriggerInteraction.Ignore))
         {
             groundedTransform     = raycastHit.collider.transform;
             oldGroundedPosition   = raycastHit.point;
             groundedLocalPosition = groundedTransform.InverseTransformPoint(oldGroundedPosition);
             oldGroundedRotation   = groundedTransform.rotation;
         }
     }
 }
示例#2
0
 // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
 override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     if (target == null)
     {
         animator.SetBool("PowerUpInSight", false);
     }
     else if (playerController.state == MinifigControllerWTH.State.Idle)
     {
         currentPath = new NavMeshPath();
         NavMesh.CalculatePath(player.transform.position, target.position, NavMesh.AllAreas, currentPath);
         if (currentPath.corners.Length < 2)
         {
             animator.SetBool("PowerUpInSight", false);
         }
         else
         {
             if (Vector3.Distance(player.transform.position, currentPath.corners[1]) > 0.5f)
             {
                 playerController.MoveTo(currentPath.corners[1]);
             }
             else if (currentPath.corners.Length > 2)
             {
                 Vector3 jumpGoal = currentPath.corners[2];
                 playerController.MoveTo(jumpGoal);
                 playerController.AddForce(new Vector3(0, playerController.jumpSpeed, 0));
             }
         }
     }
 }
示例#3
0
 // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
 override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     animator.SetBool("IsInMiddle", isPlayerInMiddle(player.transform.position));
     animator.SetBool("PlayerInSight", playerInRange(player.transform.position));
     animator.SetBool("PowerUpInSight", powerUpInRange(player.transform.position));
     if (playerController.state == MinifigControllerWTH.State.Idle)
     {
         currentPath = new NavMeshPath();
         Vector3 targetPosition = new Vector3(0, 0, 0);
         if (playerController.hasPowerUp())
         {
             playerController.SpawnPowerUp();
             playerController.MoveTo(targetPosition, maxMoveTime: 1.5f);
         }
         else
         {
             NavMesh.CalculatePath(player.transform.position, targetPosition, NavMesh.AllAreas, currentPath);
             if (currentPath.corners.Length >= 2)
             {
                 if (Vector3.Distance(player.transform.position, currentPath.corners[1]) > 0.5f)
                 {
                     playerController.MoveTo(currentPath.corners[1]);
                 }
                 else if (currentPath.corners.Length > 2)
                 {
                     Vector3 jumpGoal = currentPath.corners[2];
                     playerController.MoveTo(jumpGoal);
                     playerController.AddForce(new Vector3(0, playerController.jumpSpeed, 0));
                 }
             }
         }
     }
 }
示例#4
0
 private void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.tag == "Player")
     {
         MinifigControllerWTH controller = collision.gameObject.GetComponent <MinifigControllerWTH>();
         Vector3 bounce = new Vector3(0, bounciness, 0);
         controller.AddForce(bounce);
     }
 }
示例#5
0
 private void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.tag == "Player")
     {
         GameObject           collidedPlayer = collision.gameObject;
         MinifigControllerWTH controller     = collidedPlayer.GetComponent <MinifigControllerWTH>();
         if (!(controller == this.gameObject.GetComponentInParent <MinifigControllerWTH>()))
         {
             Vector3 pushDir = collidedPlayer.transform.position - transform.position;
             pushDir  *= batPower;
             pushDir.y = homerunHeight;
             controller.AddForce(pushDir);
             Debug.Log("Schläger hat Spieler getroffen. Spieler fliegt richtung " + pushDir.ToString());
         }
     }
 }