private bool CheckIfGrounded() // 计算射线的原点 Vector3 rayOrigin = transform.position + rayOriginOffset; // 执行射线投射 if (Physics.Raycast(rayOrigin, Vector3.down, out RaycastHit hit, rayLength, groundLayers)) { // 如果射线在指定距离内击中某物且在地面层上,我们就接地了 return true; }...
private Transform groundCheck; // A position marking where to check if the player is grounded. private bool grounded = false; // Whether or not the player is grounded. private Animator anim; // Reference to the player's animator component. void Awake() { // Setting up references. // 在...
//SkeletonGroundedState:骷髅接地状态usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassSkeletonGroundedState:EnemyState{protectedEnemy_Skeletonenemy;publicSkeletonGroundedState(EnemyStateMachine_stateMachine,Enemy_enemyBase,Enemy_Skeleton_enemy,string_animBoolName):base(_stateMachine,_ene...
checkResult = Physics2D.Linecast(transform.position, groundChecks[i].position, 1 << LayerMask.NameToLayer("Ground")); vida.grounded = checkResult; if (vida.grounded) break; } if (vida.grounded) { //火箭蛋(硬件蛋特殊技能) if (vida.playerType == Tags.YingjianDan) { vida.jumpable = 1...
checkResult = Physics2D.Linecast(transform.position, groundChecks[i].position,1<< LayerMask.NameToLayer("Ground")); vida.grounded = checkResult;if(vida.grounded)break; }if(vida.grounded) {//火箭蛋(硬件蛋特殊技能)if(vida.playerType == Tags.YingjianDan) ...
LogicUpdate(); xInput = player.InputManage.NormInputX; yInput = player.InputManage.NormInputY; } public override void PhysicsUpdate() { base.PhysicsUpdate(); } } 因为玩家执行待机以及移动状态时是在地上的,所以需要继承 PlayerGroundedState 这个状态。我们可以先思考一下:在待机状态需要检测什么,以及...
// 是否在地面的标记 private Transform m_GroundCheck; // 检测是否在地面的位置 const float k_GroundedRadius = .2f; // 周身范围检测是否在地面 private bool m_Grounded; // 是否在地面 private Transform m_CeilingCheck; // 是否到顶了的位置 const float k_Ceilin...
whenever your player is grounded and moving. Here's an example: private void DoMovement() { if (isGrounded && hasMovementInput) { stepHeightController.CheckForStep(); // Integrate the step detection } // Your custom movement logic here ...
if (hit.collider != null)isGround = true;else isGround = false;} 2.Unity官⽅的Character Controller 直接给⾓⾊加⼊Character Controller组件,在脚本中Get到Character Controller,调⽤.isGrounded即可,但是实际效果让⼈失望 因为.isGrounded是当⾓⾊移动的时候才会检测是否着地的,也就是说它只能在...
}// Update is called once per framevoidUpdate(){ MoveMent(); }voidMoveMent(){ isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);//检测是否在地面if(isGrounded && velocity.y <0) {//防止在真正掉落到地面前 停止掉落velocity.y =-2; ...