调整GroundCheck的位置到角色脚下 调整GroundCheckDistance使GroundCheck大小合适 同样的操作设置好wallCheck (三)调用rayCast实现碰撞检测 添加layerMask过滤器,仅在Ground层上检测碰撞体。 [SerializeField]privateLayerMaskwhatIsGround; 选择平台添加Ground层 Layer->Add Layer->定义Ground层 点击平台,在Layer选项中就可以看到...
Raycast(groundCheck.position, Vector2.down, groundCheckDistance, whatIsGround); public bool isWallDetected() => Physics2D.Raycast(wallCheck.position,Vector2.right * facingDir,wallCheckDistance,whatIsGround); //绘制碰撞检测 private void OnDrawGizmos() { Gizmos.DrawLine(groundCheck.position, new ...
floatdt = Time.deltaTime;//累计时间vida.chargeTimer += dt; vida.jumpTimer += dt;//TODO 待优化代码//是否到地面 用三个groundCheck来检测//public Transform[] groundChecks = new Transform[3];for(inti =0; i <3; ++i) { checkResult = Physics2D.Linecast(transform.position, groundChecks[i]...
RayCheck();//射线检测}privatevoidRayCheck(){floatxOffset = playerStandSize.x /2;floatyOffset = -playerStandSize.y /2+ playerStandOffset.y;//碰撞体左下角位置 (-xOffset, yOffset)RaycastHit2D leftFootCheck = Raycast(newVector2(-xOffset, yOffset), Vector2.down,0.2f, groundLayer);//碰撞...
可以用Raycast来检测角色落地,但更简单的方法是判断角色下方的坐标是否在地面以下。在Controls脚本中新建一个Transform,命名为groundCheck,就是角色下方的坐标。并添加一些其它的变量: [C#] 纯文本查看 复制代码 ? public Transform groundCheck; public float groundCheckRadius; public LayerMask whatIsGround; private ...
publicvoidCheckIsOnHorizontalGround(){// 调用(1)中方法,生成玩家左侧检测射线RaycastHit2DleftCheckRay=CreateOffsetRaycast(newVector2(-0.5f,0.0f),Vector2down),0.51f,groundLayer);// 调用(1)中方法,生成玩家右侧检测射线RaycasHit2DrightCheckRay=CreateOffsetRaycast(newVector2(0.5f,0.0f),Vector2down),0.5...
public class RaycastTest : MonoBehaviour { private bool isGround = false; private Rigidbody2D myRigidbody2D; void Awake () { myAnimator = GetComponent<Animator>(); myRigidbody2D = GetComponent<Rigidbody2D>(); } void FixedUpdate () {
groundCheck = transform.Find("groundCheck"); // 获取当前的动画控制器 anim = GetComponent<Animator>(); } void Update() { // 是为能随时检测到groundCheck这个物体,添加一个名叫Ground的Layer,然后把场景中的所有代表地面的物体的Layer设为Ground ...
public class RaycastTest : MonoBehaviour { private bool isGround = false;private Rigidbody2D myRigidbody2D;void Awake () { myAnimator = GetComponent<Animator>();myRigidbody2D = GetComponent<Rigidbody2D>();} void FixedUpdate () { Debug.DrawRay(transform.position, Vector2.down * 0.11f, Color...
添加一个新的layer,命名为Ground,并将上面建立的plane设置为Ground层 在plane上添加若干个box作为障碍物,添加一个新的layer,命名为Obstacles, 将这些box都归为这个Obstacles层 2.加入A* 创建一个空的GameObject,命名为A*, 从Components–>Pathfinding–>Pathfinder中添加插件脚本AstarPath。可以再AstarPath的观察器中看...