void FindSpot(RaycastHit _hit, CheckingSort _currentChekingSort) { if (Vector3.Angle(_hit.normal, Vector3.up) < maxAngle) { RayInfo _rayInfo = new RayInfo(); if (_currentChekingSort == CheckingSort.normal) { _rayInfo = GetClosestPoint(_hit.transform, _hit.point + new Vector3(0, -.01f, 0), transform.forward / 2.5f); } else if (_currentChekingSort == CheckingSort.turning) { _rayInfo = GetClosestPoint(_hit.transform, _hit.point + new Vector3(0, -.01f, 0), transform.forward / 2.5f - transform.right * Input.GetAxis("Horizontal")); } else if (_currentChekingSort == CheckingSort.falling) { _rayInfo = GetClosestPoint(_hit.transform, _hit.point + new Vector3(0, -.01f, 0), -transform.forward / 2.5f); } targetPoint = _rayInfo.Point; targetNormal = _rayInfo.Normal; if (_rayInfo.CanGoToPoint) { if (currentClimbSort != ClimbSort.Climbing && currentClimbSort != ClimbSort.ClimbingTowardsPoint) { tPUC.enabled = false; rigidbodyPlayer.isKinematic = true; tPC.m_IsGrounded = false; //tPC.IsGrounded = false; } currentClimbSort = ClimbSort.ClimbingTowardsPoint; beginDistance = Vector3.Distance(transform.position, (targetPoint - transform.rotation * handTransform.localPosition)); } } }
void CheckForSpots(Vector3 _spotLocation, Vector3 _direction, float _range, CheckingSort _currentChekingSort) { bool _foundSpot = false; RaycastHit _hit; if (Physics.Raycast(_spotLocation - transform.right * smallEdge / 2, _direction, out _hit, _range, whatsClimbable)) { Debug.DrawRay(_spotLocation - transform.right * smallEdge / 2, _direction, Color.red); if (Vector3.Distance(handTransform.position, _hit.point) > minDistance) { _foundSpot = true; FindSpot(_hit, _currentChekingSort); } } if (!_foundSpot) { if (Physics.Raycast(_spotLocation + transform.right * smallEdge / 2, _direction, out _hit, _range, whatsClimbable)) { Debug.DrawRay(_spotLocation + transform.right * smallEdge / 2, _direction, Color.cyan); if (Vector3.Distance(handTransform.position, _hit.point) > minDistance) { _foundSpot = true; FindSpot(_hit, _currentChekingSort); } } } if (!_foundSpot) { if (Physics.Raycast(_spotLocation - transform.right * smallEdge / 2 + transform.forward * smallEdge, _direction, out _hit, _range, whatsClimbable)) { Debug.DrawRay(_spotLocation - transform.right * smallEdge / 2 + transform.forward * smallEdge, _direction, Color.yellow); if (Vector3.Distance(handTransform.position, _hit.point) - smallEdge / 1.5f > minDistance) { _foundSpot = true; FindSpot(_hit, _currentChekingSort); } } } if (!_foundSpot) { if (Physics.Raycast(_spotLocation + transform.right * smallEdge / 2 + transform.forward * smallEdge, _direction, out _hit, _range, whatsClimbable)) { Debug.DrawRay(_spotLocation + transform.right * smallEdge / 2 + transform.forward * smallEdge, _direction, Color.green); if (Vector3.Distance(handTransform.position, _hit.point) - smallEdge / 1.5f > minDistance) { _foundSpot = true; FindSpot(_hit, _currentChekingSort); } } } }
public void CheckForSpots(Vector3 SpotLocation, Vector3 dir, float range, CheckingSort sort) { bool foundSpot = false; if (Physics.Raycast(SpotLocation - transform.right * SmallesEdge / 2, dir, out hit, range, SpotLayer)) { if (Vector3.Distance(HandTrans.position, hit.point) > minDistance) { foundSpot = true; FindSpot(hit, sort); } } if (!foundSpot) { if (Physics.Raycast(SpotLocation + transform.right * SmallesEdge / 2, dir, out hit, range, SpotLayer)) { if (Vector3.Distance(HandTrans.position, hit.point) > minDistance) { foundSpot = true; FindSpot(hit, sort); } } } if (!foundSpot) { if (Physics.Raycast(SpotLocation + transform.right * SmallesEdge / 2 + transform.forward * SmallesEdge, dir, out hit, range, SpotLayer)) { if (Vector3.Distance(HandTrans.position, hit.point) - SmallesEdge / 1.5f > minDistance) { foundSpot = true; FindSpot(hit, sort); } } } if (!foundSpot) { if (Physics.Raycast(SpotLocation - transform.right * SmallesEdge / 2 + transform.forward * SmallesEdge, dir, out hit, range, SpotLayer)) { if (Vector3.Distance(HandTrans.position, hit.point) - SmallesEdge / 1.5f > minDistance) { foundSpot = true; FindSpot(hit, sort); } } } }
/// <summary> /// 查找墙边点 改变状态 /// </summary> /// <param name="h">所使用检测到的射线</param> /// <param name="sort">当前的状态</param> public void FindSpot(RaycastHit h, CheckingSort sort) { //若是该攀爬点跟世界的角度过大(过于倾斜),则不能抓 if (Vector3.Angle(h.normal, Vector3.up) < MaxAngle) { if (sort == CheckingSort.nomal) { nextClimbPoint = GetClosetPoint(h.transform, h.point + new Vector3(0, -0.01f, 0), transform.forward / 2.5f); } else if (sort == CheckingSort.turning) { nextClimbPoint = GetClosetPoint(h.transform, h.point + new Vector3(0, -0.01f, 0), transform.forward / 2.5f - transform.right * Input.GetAxis("Horizontal")); } else if (sort == CheckingSort.falling) { nextClimbPoint = GetClosetPoint(h.transform, h.point + new Vector3(0, -0.01f, 0), -transform.forward / 2.5f); } Debug.Log("nextClimbPoint111111111 = " + nextClimbPoint.point); } }
/// <summary> /// 查找墙边点 改变状态 /// </summary> /// <param name="h">所使用检测到的射线</param> /// <param name="sort">当前的状态</param> #region public void FindSpot(RaycastHit h, CheckingSort sort) { //若是该攀爬点跟世界的角度过大(过于倾斜),则不能抓 if (Vector3.Angle(h.normal, Vector3.up) < MaxAngle) { RayInfo ray = new RayInfo(); if (sort == CheckingSort.nomal) { ray = GetClosetPoint(h.transform, h.point + new Vector3(0, -0.01f, 0), transform.forward / 2.5f); } else if (sort == CheckingSort.turning) { ray = GetClosetPoint(h.transform, h.point + new Vector3(0, -0.01f, 0), transform.forward / 2.5f - transform.right * Input.GetAxis("Horizontal")); } else if (sort == CheckingSort.falling) { ray = GetClosetPoint(h.transform, h.point + new Vector3(0, -0.01f, 0), -transform.forward / 2.5f); } TargetPoint = ray.point; TargetNormal = ray.nomal; //如果该点能攀爬 if (ray.CanGoToPoint) { //若不是攀爬状态,并且不是爬动状态 if (currentSort != Climbingsort.Climbing && currentSort != Climbingsort.ClimbingTowardsPoint) { //爬向最近的spot.爬动时人物控制取消,刚体取消,不在地上 Debug.Log("FindSpot::找到要爬的点了 TargetPoint = " + TargetPoint); rigid.isKinematic = true; TPUC.enabled = false; TPC.m_IsGrounded = false; } currentSort = Climbingsort.ClimbingTowardsPoint; BeginDistance = Vector3.Distance(transform.position, (TargetPoint - transform.rotation * HandTrans.localPosition)); } } }
public void FindSpot(RaycastHit h, CheckingSort sort) { if (Vector3.Angle(h.normal, Vector3.up) < MaxAngle) { RayInfo ray = new RayInfo(); if (sort == CheckingSort.normal) { ray = GetClosestPoint(h.transform, h.point + new Vector3(0, -0.01f, 0), transform.forward / 2.5f); } else if (sort == CheckingSort.turning) { ray = GetClosestPoint(h.transform, h.point + new Vector3(0, -0.01f, 0), transform.forward / 2.5f - transform.right * Input.GetAxis("Horizontal")); } else if (sort == CheckingSort.falling) { ray = GetClosestPoint(h.transform, h.point + new Vector3(0, -0.01f, 0), -transform.forward / 2.5f); } TargetPoint = ray.point; TargetNormal = ray.normal; if (ray.CanGoToPoint) { if (currentSort != Climbingsort.Climbing && currentSort != Climbingsort.ClimbingTowardsPoint) { TPUC.enabled = false; rigid.isKinematic = true; TPC.m_IsGrounded = false; } currentSort = Climbingsort.ClimbingTowardsPoint; BeginDistance = Vector3.Distance(transform.position, (TargetPoint - transform.rotation * HandTrans.localPosition)); } } }