Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Bằng cách này, vũ khí được cập nhật theo tay phải của người chơi. Bạn cũng cần để thiết lập hướng mục tiêu của vũ khí như hướng phía trước của người chơi (như minh họa trong hình 12-9). Lưu ý rằng bạn cần phải chuyển đổi xương bàn tay phải của người chơi của người chơi ma trận chuyển đổi trước | CHAPTER 12 CREATING A THIRD-PERSON SHOOTER GAME 379 You update the player s weapon by calling the weapon s Update method and passing the player s right hand bone as the weapon s parent bone. In this way the weapon is updated according to the player s right hand. You also need to set the weapon s target direction as the player s front direction as illustrated in Figure 12-9 . Note that you need to transform the player s right hand bone by the player s transformation matrix before using it to update the player s weapon. Following is the code for the player s Update methods public override void Update GameTime time Update the player s waist bone float elapsedTimeSeconds float time.ElapsedGameTime.TotalSeconds UpdateWaistBone elapsedTimeSeconds Update player s base class It s where the player s position and animated model are updated base.Update time Update camera chase position UpdateChasePosition Update player weapon Matrix transformedHand AnimatedModel.BonesAnimation RIGHT_HAND_BONE_ID Transformation.Matrix playerWeapon.Update time transformedHand playerWeapon.TargetDirection HeadingVector UpVector rotateWaistBone Enemy The Enemy class is the one that has the enemy NPC s logic and attributes. Figure 12-10 exhibits a spider model used as an enemy in the game. 380 CHAPTER 12 CREATING A THIRD-PERSON SHOOTER GAME Figure 12-10. An alien spider model. Courtesy of Psionic http www.psionic3d.co.uk . Differently from the player the enemy is computer controlled so you need to implement its AI. The enemy s AI is simple having only four different states Wandering Chasing Player Attacking Player and Dead. Figure 12-11 shows the diagram of the AI built for the enemies. Figure 12-11. Enemy AI diagram CHAPTER 12 CREATING A THIRD-PERSON SHOOTER GAME 381 In the AI diagram in Figure 12-11 each circle represents a different enemy state and the arrows represent the actions that make an enemy change its state. The enemy s AI starts in the Wandering state. In this state the enemy keeps .