调整GroundCheck的位置到角色脚下 调整GroundCheckDistance使GroundCheck大小合适 同样的操作设置好wallCheck (三)调用rayCast实现碰撞检测 添加layerMask过滤器,仅在Ground层上检测碰撞体。 [SerializeField]privateLayerMaskwhatIsGround; 选择平台添加Ground层 Layer->Add Layer->定义Ground层 点击平台,在Layer选项中就可以看到...
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]...
} 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) { i...
//是否到地面 用三个groundCheck来检测 //public Transform[] groundChecks = new Transform[3]; for (int i = 0; i < 3; ++i) { checkResult = Physics2D.Linecast(transform.position, groundChecks[i].position, 1 << LayerMask.NameToLayer("Ground")); vida.grounded = checkResult; if (vida....
Offset.y;//碰撞体左下角位置 (-xOffset, yOffset)RaycastHit2D leftFootCheck = Raycast(newVector2(-xOffset, yOffset), Vector2.down,0.2f, groundLayer);//碰撞体右下角位置 (xOffset, yOffset)RaycastHit2D rightFootCheck = Raycast(newVector2(xOffset, yOffset), Vector2.down,0.2f, 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...
RaycastHit hitInfo; #if UNITY_EDITOR // 在场景中显示地面检查线,从脚上0.1米处往下射m_GroundCheckDistance的距离,预制体默认是0.3 Debug.DrawLine(transform.position (Vector3.up * 0.1f), transform.position (Vector3.up * 0.1f) (Vector3.down * m_GroundCheckDistance)); ...
RaycastHit hit; if(!Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition),outhit, 100)) return; // We need to hit something (with a collider on it) if(!hit.transform) return; // Get input vector from kayboard or analog stick and make it length 1 at most ...
// 在子对象里面找到groundCheck groundCheck = transform.Find("groundCheck"); // 获取当前的动画控制器 anim = GetComponent<Animator>(); } void Update() { // 是为能随时检测到groundCheck这个物体,添加一个名叫Ground的Layer,然后把场景中的所有代表地面的物体的Layer设为Ground ...
RaycastHit hit; if(!Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition),outhit, 100)) return; // We need to hit something (with a collider on it) if(!hit.transform) return; // Get input vector from kayboard or analog stick and make it length 1 at most ...