//private void ShowModelUIName() //{ // foreach (var item in DataController.instance.ActorList) // { // if (item.Key != DataController.instance.MyLocateIndex) // { // memberGroup[item.Value.UniqueID].ShowMyName(item.Value.Register.name); // } // } //} /// <summary> /// 刷新3D模型的显示 /// </summary> private void UpdateRoomActor() { GameObject obj = null; for (int i = 0; i < DataController.instance.MyRoomInfo.Limit; i++) { RoomActor info = DataController.instance.ActorList[i]; if (!memberGroup.ContainsKey(i)) { Debug.Log("初始化其他玩家模型站位:" + i); memberGroup.Add(i, null); } CharacterCommon mControl = memberGroup[i]; if (mControl == null)//初始化生成 { obj = PoolManager.instance.GetPoolObjByType(PreLoadType.Member, transActor); mControl = obj.GetComponent <CharacterCommon>(); memberGroup[i] = mControl; } if (DataController.instance.ActorList[i] == null)//该位置玩家退出或不存在 { mControl.gameObject.SetActive(false); } else { mControl.gameObject.SetActive(true); mControl.Init(info.UniqueID); mControl.ShowTeam(DataController.instance.ActorList[i].MyTeam); } } }
void Awake() { attackChecker = transform.Find("Sensors/Attack").GetComponent <CharacterAttackChecker>(); playerTrans = GameObject.FindGameObjectWithTag("Player").transform; monsterCommon = GetComponent <CharacterCommon>(); }
void FixedUpdate() { float inputForward = 0f; float inputTurn = 0f; // input is polled in the Update() step, not FixedUpdate() // Therefore, you should ONLY use input state that is NOT event-based in FixedUpdate() // Input events should be handled in Update(), and possibly passed on to FixedUpdate() through // the state of the MonoBehavior if (cinput.enabled) { inputForward = cinput.Forward; inputTurn = cinput.Turn; } //onCollisionStay() doesn't always work for checking if the character is grounded from a playability perspective //Uneven terrain can cause the player to become technically airborne, but so close the player thinks they're touching ground. //Therefore, an additional raycast approach is used to check for close ground if (CharacterCommon.CheckGroundNear(this.transform.position, jumpableGroundNormalMaxAngle, 1.5f, 1f, out closeToJumpableGround)) { isGrounded = true; } anim.SetFloat("velx", inputTurn); anim.SetFloat("vely", inputForward); anim.SetBool("isFalling", !isGrounded); }
void Awake() { animator = GetComponent <Animator>(); characterInfor = GetComponent <CharacterInformation>(); player = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerControl>(); characterCommon = GetComponent <CharacterCommon>(); }
void Update() { float inputTurn = Input.GetAxis("Horizontal"); float inputForward = Input.GetAxis("Vertical"); bool inputJump = Input.GetButtonDown("Jump"); //onCollisionXXX() doesn't always work for checking if the character is grounded from a playability perspective //Uneven terrain can cause the player to become technically airborne, but so close the player thinks they're touching ground. //Therefore, an additional raycast approach is used to check for close ground bool isGrounded = grounded || CharacterCommon.CheckGroundNear(this.transform.position, jumpableGroundNormalMaxAngle, 0.85f, 0f, out closeToJumpableGround); if (inputJump && (isGrounded || !doubleJumped)) { rbody.velocity = new Vector3(rbody.velocity.x, 5, rbody.velocity.z); if (!isGrounded) { doubleJumped = true; } } anim.SetFloat("velx", inputTurn); anim.SetFloat("vely", inputForward); anim.SetBool("isFalling", !isGrounded); }
public BulletInfo RayShoot() { BulletInfo bulletInfo = new BulletInfo(); Ray ray = new Ray(transform.position, transform.forward); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { // 如果射线与平面碰撞,打印碰撞物体信息 Debug.Log("碰撞对象: " + hit.collider.name); // 在场景视图中绘制射线 Debug.DrawLine(ray.origin, hit.point, Color.red); GameObject obj = hit.transform.gameObject; switch (obj.tag) { case nameof(Tag.Box): Box box = obj.GetComponent <Box>(); bulletInfo.shootTag = ShootTag.Box; bulletInfo.shootInfo = box.myInfo.myIndex + ""; break; case nameof(Tag.Member): CharacterCommon member = obj.GetComponent <CharacterCommon>(); bulletInfo.shootTag = ShootTag.Character; bulletInfo.shootInfo = member.myIndex + ""; break; default: //墙体及障碍物 bulletInfo.shootTag = ShootTag.Wall; break; } } return(null); }
void OnAnimatorMove() { Vector3 newRootPosition; Quaternion newRootRotation; bool isGrounded = IsGrounded || CharacterCommon.CheckGroundNear(this.transform.position, jumpableGroundNormalMaxAngle, 0.85f, 0f, out closeToJumpableGround); if (isGrounded) { //use root motion as is if on the ground newRootPosition = anim.rootPosition; } else { //Simple trick to keep model from climbing other rigidbodies that aren't the ground newRootPosition = new Vector3(anim.rootPosition.x, this.transform.position.y, anim.rootPosition.z); } //use rotational root motion as is newRootRotation = anim.rootRotation; //TODO Here, you could scale the difference in position and rotation to make the character go faster or slower this.transform.position = newRootPosition; this.transform.rotation = newRootRotation; }
void Awake() { health = GetComponent <CharacterHealth>(); animator = GetComponent <Animator>(); rigid2D = GetComponent <Rigidbody2D>(); characterCommon = GetComponent <CharacterCommon>(); }
void Awake() { normalChecker = transform.Find("Sensors/SkillQNormalAttack").GetComponent <CharacterAttackChecker>(); powerChecker = transform.Find("Sensors/SkillQPowerAttack").GetComponent <CharacterAttackChecker>(); characterCommon = GetComponent <CharacterCommon>(); source = GetComponent <AudioSource>(); player = GetComponent <PlayerControl>(); }
/// <summary> /// 模型加载完成,设置初始状态 /// </summary> private void SetPrepareData(GameModelData info) { CharacterCommon member = null; member = GameManager.instance.memberGroup[info.userIndex]; member.SetPosition(SerializeHelper.BackVector(info.pos)); //member.SetRotate(SerializeHelper.BackVector(info.rotate)); member.SetAnimation(info.animation); }
void Awake() { player = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerControl>(); playerCommon = player.GetComponent <CharacterCommon>(); monster = GetComponent <MonsterControll>(); monsterCommon = GetComponent <CharacterCommon>(); monsterInfor = GetComponent <CharacterInformation>(); attackLocation = transform.Find("Effect/Attack"); }
void Update() { // // Event-based inputs need to be handled in Update() if (cinput.Interact && !debounceInteractButton) { EventManager.instance.ActionButtonPressed(); debounceInteractButton = true; } else if (!cinput.Interact && debounceInteractButton) { debounceInteractButton = false; } if (cinput.Action && !debounceActionButton) { if (pickedUpItem) { _putdown_item(); } else { GameObject target = CharacterCommon.CheckForNearestPickupableItem(transform, 100f); if (target) { _pickup_item(target); } } debounceActionButton = true; } else if (!cinput.Action && debounceActionButton) { debounceActionButton = false; } if (pickedUpItem) { if (!itemInPosition && pickedUpItem.transform.position == HoldSpot.transform.position) { itemInPosition = true; } if (!itemInPosition) { pickedUpItem.transform.position += (HoldSpot.transform.position - pickedUpItem.transform.position) * (Time.deltaTime * pickupSpeed); } else { pickedUpItem.transform.position = HoldSpot.transform.position; } } anim.speed = animationSpeed; }
// Update is called once per frame void Update() { bool isGrounded = IsGrounded || CharacterCommon.CheckGroundNear(this.transform.position, jumpableGroundNormalMaxAngle, 0.1f, 1f, out closeToJumpableGround); if (isGrounded) { if (Input.GetKeyDown(KeyCode.Space)) { Vector3 jump = new Vector3(0.0f, 150.0f, 0.0f); rb.AddForce(jump * jumpHeight, ForceMode.Impulse); anim.SetBool("is_in_air", true); } else { anim.SetBool("is_in_air", false); } } float moveHorizontal = Input.GetAxisRaw("Horizontal"); float moveVertical = Input.GetAxisRaw("Vertical"); // logic for compatibility for third person camera Vector3 direction = new Vector3(moveHorizontal, 0.0f, moveVertical).normalized; //do some filtering of our input as well as clamp to a speed limit float movespeed = Mathf.Max(Mathf.Abs(moveHorizontal), Mathf.Abs(moveVertical)); filteredForwardInput = Mathf.Clamp(Mathf.Lerp(filteredForwardInput, movespeed, Time.deltaTime * forwardInputFilter), -forwardSpeedLimit, forwardSpeedLimit); // test for moving using character controller if (direction.magnitude >= 0.1f) { float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y; float smoothedAngle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime); transform.rotation = Quaternion.Euler(0f, smoothedAngle, 0f); Vector3 moveDirection = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward; //controller.Move(moveDirection.normalized * speed * Time.deltaTime); rb.MovePosition(rb.position + moveDirection.normalized * speed * Time.deltaTime); } if (Input.GetKeyUp(KeyCode.Escape)) { if (!gameEnded) { PauseMenuToggle pauseMenuScript = InGameMenu.GetComponent <PauseMenuToggle>(); pauseMenuScript.PauseMenuInteraction(); } } anim.SetFloat("velocity", filteredForwardInput); }
void Awake() { player = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerControl>(); player.GetComponent <CharacterCommon>(); GetComponent <MonsterControll>(); monsterCommon = GetComponent <CharacterCommon>(); GetComponent <CharacterInformation>(); attackLocation = transform.Find("Effect/Attack"); PowerEffectController.OnShoot += OnShoot; powerAnimator = PowerEffectController.GetComponent <Animator>(); }
void Awake() { // Setting up references. groundChecker = transform.Find("Checkers/Ground"); anim = GetComponent <Animator>(); anim.enabled = false; rigid2D = GetComponent <Rigidbody2D>(); characterCommon = GetComponent <CharacterCommon>(); characterHealth = GetComponent <CharacterHealth>(); }
void OnCollisionEnter(Collision hit) { rb.useGravity = false; GameObject obj = hit.gameObject; switch (obj.tag) { case nameof(Tag.Member): Debug.LogError("Buff:" + myInfo.myIndex + "->" + obj.name); CharacterCommon cha = obj.GetComponent <CharacterCommon>(); BePickUp(cha.myIndex); break; } }
void FixedUpdate() { float inputForward = 0f; float inputTurn = 0f; if (cinput.enabled) { inputForward = cinput.Forward; inputTurn = cinput.Turn; } //switch turn around if going backwards if (inputForward < 0f) { inputTurn = -inputTurn; } //onCollisionStay() doesn't always work for checking if the character is grounded from a playability perspective //Uneven terrain can cause the player to become technically airborne, but so close the player thinks they're touching ground. //Therefore, an additional raycast approach is used to check for close ground if (CharacterCommon.CheckGroundNear(this.transform.position, jumpableGroundNormalMaxAngle, 0.1f, 1f, out closeToJumpableGround)) { isGrounded = true; } //this.transform.Translate(Vector3.forward * cinput.Forward * Time.deltaTime * forwardMaxSpeed); //this.transform.Rotate(Vector3.up, cinput.Turn * Time.deltaTime * turnMaxSpeed); //It's supposed to be safe to not scale with Time.deltaTime (e.g. framerate correction) within FixedUpdate() //If you want to make that optimization, you can precompute your velocity-based translation using Time.fixedDeltaTime //We use rbody.MovePosition() as it's the most efficient and safest way to directly control position in Unity's Physics rbody.MovePosition(rbody.position + this.transform.forward * inputForward * Time.deltaTime * forwardMaxSpeed); //Most characters use capsule colliders constrained to not rotate around X or Z axis //However, it's also good to freeze rotation around the Y axis too. This is because friction against walls/corners //can turn the character. This errant turn is disorienting to players. //Luckily, we can break the frozen Y axis constraint with rbody.MoveRotation() //BTW, quaternions multiplied has the effect of adding the rotations together rbody.MoveRotation(rbody.rotation * Quaternion.AngleAxis(inputTurn * Time.deltaTime * turnMaxSpeed, Vector3.up)); //anim.SetFloat("velx", inputTurn); anim.SetFloat("vely", inputForward); anim.SetBool("isFalling", !isGrounded); //clear for next OnCollisionStay() callback isGrounded = false; }
void FixedUpdate() { float inputForward = 0f; float inputTurn = 0f; if (cinput.enabled) { inputForward = cinput.Forward; inputTurn = cinput.Turn; } //onCollisionXXX() doesn't always work for checking if the character is grounded from a playability perspective //Uneven terrain can cause the player to become technically airborne, but so close the player thinks they're touching ground. //Therefore, an additional raycast approach is used to check for close ground bool isGrounded = IsGrounded || CharacterCommon.CheckGroundNear(this.transform.position, jumpableGroundNormalMaxAngle, 0.85f, 0f, out closeToJumpableGround); anim.SetFloat("velx", inputTurn); anim.SetFloat("vely", inputForward); anim.SetBool("isFalling", !isGrounded); }
public void Init(GameObject characterObject, iPlayer player) { GameObject = characterObject; this.player = player; Animator = GameObject.GetComponent <Animator>(); Inputs = GameObject.GetComponent <CharacterInputs>(); Common = new CharacterCommon(this); controller = new FSMController <CharacterController, eStates>(this); controller.RegisterState(eStates.Idle, new CharacterIdle()); controller.RegisterState(eStates.Walk, new CharacterIdleWalk()); controller.RegisterState(eStates.Jump, new CharacterJump()); controller.RegisterState(eStates.Falling, new CharacterFalling()); controller.AddMapping(eStates.Idle, eStates.Jump, eStates.Walk, eStates.Falling); controller.AddMapping(eStates.Walk, eStates.Jump, eStates.Idle, eStates.Falling); controller.AddMapping(eStates.Jump, eStates.Idle, eStates.Walk, eStates.Falling); controller.AddMapping(eStates.Falling, eStates.Idle, eStates.Walk, eStates.Jump); controller.SetLogToGUI(true, 1); controller.SetState(eStates.Idle); }
private void OnTriggerEnter(Collider other) { CharacterCommon checkSelf = other.GetComponent <CharacterCommon>(); if (checkSelf != null) { if (checkSelf.myIndex == info.userIndex)//子弹碰撞的是子弹的主人,不处理,不停止 { return; } } //自身被射检测以后再判断其他 if (!isDestroy) { isDestroy = true; bool isSend = (ownIndex == DataController.instance.MyLocateIndex); GameObject obj = other.gameObject; BulletInfo bulletInfo = new BulletInfo() { userIndex = DataController.instance.MyLocateIndex }; switch (obj.tag) { case nameof(Tag.Box): Box box = obj.GetComponent <Box>(); bulletInfo.shootTag = ShootTag.Box; bulletInfo.shootInfo = box.myInfo.myIndex + ""; if (isSend) //本人射击 { TeamType type = DataController.instance.ActorList[DataController.instance.MyLocateIndex].MyTeam; box.ChangeTexture(type); } break; case nameof(Tag.Member): CharacterCommon member = obj.GetComponent <CharacterCommon>(); bulletInfo.shootTag = ShootTag.Character; bulletInfo.shootInfo = member.myIndex + ""; RoomActorState state = DataController.instance.ActorList[member.myIndex].CurState; string tip = ""; switch (state) { case RoomActorState.Dead: tip = "该玩家已死亡"; break; case RoomActorState.Invincible: tip = "该玩家当前无敌"; break; } if (!string.IsNullOrEmpty(tip)) { UIManager.instance.ShowAlertTip(tip); isSend = false; } break; default: //墙体及障碍物 isSend = false; break; } Debug.Log("射中:" + bulletInfo.shootTag); if (isSend) { GameManager.instance.SendNetInfo(bulletInfo); } // PoolDestory(); } }
void Awake() { player = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerControl>(); characterCommon = player.GetComponent <CharacterCommon>(); }
public void Init(CharacterCommon target, string name) { txName.text = name; Head = target.cameraParent; UI = this.transform; }
void Awake() { characterCommon = SourceCharacter.GetComponent <CharacterCommon>(); characterInfor = SourceCharacter.GetComponent <CharacterInformation>(); }
void Awake() { monsterControll = GetComponent <MonsterControll>(); characterCommon = GetComponent <CharacterCommon>(); }
// Update is called once per frame void Update() { //onCollisionStay() doesn't always work for checking if the character is grounded from a playability perspective //Uneven terrain can cause the player to become technically airborne, but so close the player thinks they're touching ground. //Therefore, an additional raycast approach is used to check for close ground if (CharacterCommon.CheckGroundNear(this.transform.position, jumpableGroundNormalMaxAngle, 0.1f, 1f, out closeToJumpableGround)) { isGrounded = true; } //Horizontal if (Input.GetButtonDown("Horizontal")) { isTurning = true; anim.SetBool("turn", isTurning); } if (Input.GetButton("Horizontal")) { var x = Input.GetAxis("Horizontal") * Time.deltaTime * 150f; transform.Rotate(0, x, 0); } if (Input.GetButtonUp("Horizontal")) { isTurning = false; anim.SetBool("turn", isTurning); } //Shift if (Input.GetButtonDown("Shift")) { shiftPressed = true; anim.SetBool("shift", shiftPressed); } if (Input.GetButtonUp("Shift")) { shiftPressed = false; anim.SetBool("shift", shiftPressed); } //Vertical if (Input.GetButtonDown("Vertical")) { anim.SetFloat("vert", 1f); } if (Input.GetButton("Vertical")) { if (shiftPressed) { speed = 1.7f; } else { speed = 1.3f; } var z = Input.GetAxis("Vertical") * Time.deltaTime * speed; transform.Translate(0, 0, Mathf.Abs(z)); } if (Input.GetButtonUp("Vertical")) { anim.SetFloat("vert", 0f); } //Other Functions //if (Input.GetKeyDown(KeyCode.C)) //{ // anim.SetTrigger("cry"); //} //if (Input.GetButtonDown("Fire1")) { // Vector3 dir = this.transform.position; // anim.SetTrigger("atk"); // dir = -dir.normalized; // //rb.AddForce(dir * 1000); //} if (Input.GetButtonDown("Jump")) { if (isGrounded) { anim.SetTrigger("jump"); rb.AddForce(transform.up * 200); } } anim.SetBool("isGrounded", isGrounded); isGrounded = false; }
/// <summary> /// 解析所有帧操作指令并在本客户端复现 /// </summary> /// <param name="xieyi"></param> private void SelectFrameInfo(MessageXieYi xieyi) { byte[] tempMessageContent = xieyi.MessageContent; string messageInfo = ""; CharacterCommon member = null; BuffInfo buffInfo = null; switch ((MessageConvention)xieyi.XieYiFirstFlag) { case MessageConvention.moveDirection: ActorMoveDirection moveDir = SerializeHelper.Deserialize <ActorMoveDirection>(tempMessageContent); member = GameManager.instance.memberGroup[moveDir.userIndex]; //用上次移动操作到这次操作的时间,算出当前位置,并移动到该点 //member.transform.DOMove(SerializeHelper.BackVector(moveDir.position), DataController.FrameFixedTime); //member.SetPosition(SerializeHelper.BackVector(moveDir.position)); member.SetNetDirection(moveDir); break; case MessageConvention.rotateDirection: ActorRotateDirection rotateDir = SerializeHelper.Deserialize <ActorRotateDirection>(tempMessageContent); //判断用户 //Debug.LogError("玩家接收方向移动:" + messageInfo); member = GameManager.instance.memberGroup[rotateDir.userIndex]; member.SetNetDirection(rotateDir); break; case MessageConvention.jump: ActorJump netJump = SerializeHelper.Deserialize <ActorJump>(tempMessageContent); member = GameManager.instance.memberGroup[netJump.userIndex]; member.SetJump(); break; case MessageConvention.shootBullet: ShootInfo shootInfo = SerializeHelper.Deserialize <ShootInfo>(tempMessageContent); member = GameManager.instance.memberGroup[shootInfo.userIndex]; if (shootInfo.userIndex != DataController.instance.MyLocateIndex) //自身在收到服务器消息之前已旋转 { member.ShowBullet(shootInfo); } break; case MessageConvention.bulletInfo: BulletInfo bulletInfo = SerializeHelper.Deserialize <BulletInfo>(tempMessageContent); switch (bulletInfo.shootTag) { case ShootTag.Box: BoxManager.instance.SetBulletInfo(bulletInfo); break; case ShootTag.Character: UpdateMemberShoot(xieyi); break; case ShootTag.Wall: Debug.Log("射中Wall:" + bulletInfo.shootInfo); break; case ShootTag.Buff: Debug.LogError("Buff不算是子弹"); break; } break; case MessageConvention.createBuff: buffInfo = SerializeHelper.Deserialize <BuffInfo>(tempMessageContent); GameObject obj = PoolManager.instance.GetPoolObjByType(PreLoadType.Buff, GameManager.instance.transBuff); obj.transform.position = BoxManager.instance.GetBoxInfoByIndex(buffInfo.boxIndex).transform.position; MagicBuff buff = obj.GetComponent <MagicBuff>(); buff.Init(buffInfo); break; case MessageConvention.getBuff: buffInfo = SerializeHelper.Deserialize <BuffInfo>(tempMessageContent); BoxManager.instance.SetBuffData(buffInfo); break; } }
void Update() { float inputForward = 0f; float inputTurn = 0f; bool inputAction = false; bool doButtonPress = false; bool doMatchToButtonPress = false; if (cinput.enabled) { inputForward = cinput.Forward; inputTurn = cinput.Turn; inputAction = cinput.Action; } //onCollisionXXX() doesn't always work for checking if the character is grounded from a playability perspective //Uneven terrain can cause the player to become technically airborne, but so close the player thinks they're touching ground. //Therefore, an additional raycast approach is used to check for close ground. //This is good for allowing player to jump and not be frustrated that the jump button doesn't //work bool isGrounded = IsGrounded || CharacterCommon.CheckGroundNear(this.transform.position, jumpableGroundNormalMaxAngle, 0.1f, 1f, out closeToJumpableGround); float buttonDistance = float.MaxValue; float buttonAngleDegrees = float.MaxValue; if (buttonPressStandingSpot != null) { buttonDistance = Vector3.Distance(transform.position, buttonPressStandingSpot.transform.position); buttonAngleDegrees = Quaternion.Angle(transform.rotation, buttonPressStandingSpot.transform.rotation); } if (inputAction) { Debug.Log("Action pressed"); if (buttonDistance <= buttonCloseEnoughForMatchDistance) { if (buttonDistance <= buttonCloseEnoughForPressDistance && buttonAngleDegrees <= buttonCloseEnoughForPressAngleDegrees) { Debug.Log("Button press initiated"); doButtonPress = true; } else { // TODO UNCOMMENT THESE LINES FOR TARGET MATCHING // Debug.Log("match to button initiated"); // doMatchToButtonPress = true; } } } // TODO HANDLE BUTTON MATCH TARGET HERE anim.SetFloat("velx", inputTurn); anim.SetFloat("vely", inputForward); anim.SetBool("isFalling", !isGrounded); anim.SetBool("doButtonPress", doButtonPress); anim.SetBool("matchToButtonPress", doMatchToButtonPress); }