} void PhysicsCheck() { RaycastHit2D leftFootCheck = Raycast(new Vector2(-footOffset, 0f), Vector2.down, groundDistance, groundLayer); RaycastHit2D righFootCheck = Raycast(new Vector2(footOffset, 0f), Vector2.down, groundDistance, groundLayer); if (leftFootCheck || righFootCheck) { ...
(2)使用Physics2D中的OverlapCircle方法进行检查 (问题:暂未添加由跑动到下蹲的动画状态转换逻辑) AI检测代码解析 if (!Physics2D.OverlapCircle(CellingCheck.position, 0.2f, ground))// { if (Input.GetButtonDown("Crouch")) { playerAnim.SetBool("Crouching", true); DisCollider.enabled = false; } else ...
public GameObject groundCheck; public bool isOnGround; public float Speed = 5; float xVelocity; void Start() { rb = GetComponent<Rigidbody2D>(); animator = GetComponent<Animator>(); } void Update() { isOnGround =Physics2D.OverlapCircle(groundCheck.transform.position, checkRadius,platform); Mov...
接着在Check()方法中,写入以下代码 // 墙体判断touchLeftWall = Physics2D.OverlapCircle((Vector2)transform.position +newVector2(leftOffset.x, leftOffset.y), checkRadius, groundLayer); touchRightWall = Physics2D.OverlapCircle((Vector2)transform.position +newVector2(rightOffset.x, rightOffset.y), ch...
public LayerMask whatIsGround; private bool onGround;groundCheckRadius为角色下方的坐标点指定一个范围,whatIsGround是标记地面的LayerMask,onGound则用来检测是否在地面上。再在Controls脚本中加入以下函数: [C#] 纯文本查看 复制代码 ? void FixedUpdate() { onGround = Physics2D.OverlapCircle(groundCheck.position,...
{privateRigidbody2D m_PlayerRb;//人物刚体privatefloatm_FacingRight =1;//角色是否面向右方privatefloatm_MoveInputDirection;//方向输入publicfloatm_MoveSpeed;//移动速度privateVector3 m_Velocity =Vector3.zero;privatefloatm_MovementSmoothing = .05f;//移动平滑速度publicTransform m_GroundCheck;//地面检查...
publicvoidCheckIsOnHorizontalGround(){// 调用(1)中方法,生成玩家左侧检测射线RaycastHit2DleftCheckRay=CreateOffsetRaycast(newVector2(-0.5f,0.0f),Vector2down),0.51f,groundLayer);// 调用(1)中方法,生成玩家右侧检测射线RaycasHit2DrightCheckRay=CreateOffsetRaycast(newVector2(0.5f,0.0f),Vector2down),0...
("Jump");}}}publicvoidCheckGround()//地板检测{IsGround=Physics2D.OverlapCircle(JumpBox.transform.position,0.1f,ground);IsJump=!IsGround;}publicvoidPlayFallAni()//播放下落动画{if(!IsGround&&canInput&&!IsSliding&&!IsHit){if(playerRig.velocity.y<0){playerRig.velocity+=Vector2.up*Physics2D....
private Rigidbody2D rd; public float Speed; //左右移动速度 public float jumpForce; //跳跃的力 [Header("Ground Check")] public Transform groundCheck; //检测物体的Transform public float checkRadius; //检测范围 public LayerMask groundLayer; //和groundLayer发生检测 ...
本吧热帖: 1-请问为什么我的图案的线粗细不一? 2-请教一下各位大佬关于制作教程的问题 3-百度网盘分享 ARPG项目实战:从0到上线Steam全程实录 官剑铭 4-Unity 2D游戏开发从入门到精通清华大学出版社随书资源分享 5-学习过程遇到困难 6-清华大学出版社的《Unity 2D游戏开发的