private bool CalculateHeight() { myAnimal.SetPivots(); if (!myAnimal.Pivot_Hip && !myAnimal.Pivot_Chest) { return(false); } Pivots pivot = myAnimal.Pivot_Hip ? myAnimal.Pivot_Hip : myAnimal.Pivot_Chest; Ray newHeight = new Ray() { origin = pivot.transform.position, direction = -Vector3.up * 5 }; RaycastHit hit; if (Physics.Raycast(newHeight, out hit, pivot.multiplier * myAnimal.ScaleFactor, myAnimal.GroundLayer)) { myAnimal.height = hit.distance; serializedObject.ApplyModifiedProperties(); } return(false); }
/// <summary> /// DebugOptions /// </summary> void OnDrawGizmos() { if (!debug) { return; } if (AutoSpeed) { Vector3 pos = Agent ? Agent.transform.position : transform.position; Pivots P = GetComponentInChildren <Pivots>(); pos.y = P.transform.position.y; UnityEditor.Handles.color = Color.green; UnityEditor.Handles.DrawWireDisc(pos, Vector3.up, ToRun); UnityEditor.Handles.color = Color.yellow; UnityEditor.Handles.DrawWireDisc(pos, Vector3.up, ToTrot); if (Agent) { UnityEditor.Handles.color = Color.red; UnityEditor.Handles.DrawWireDisc(pos, Vector3.up, Agent.stoppingDistance); } } }
void OnDrawGizmos() { if (!debug) { return; } if (Agent == null) { return; } if (Agent.path == null) { return; } Color lGUIColor = Gizmos.color; Gizmos.color = Color.green; for (int i = 1; i < Agent.path.corners.Length; i++) { Gizmos.DrawLine(Agent.path.corners[i - 1], Agent.path.corners[i]); } if (AutoSpeed) { Vector3 pos = Agent ? Agent.transform.position : transform.position; Pivots P = GetComponentInChildren <Pivots>(); pos.y = P.transform.position.y; UnityEditor.Handles.color = Color.green; UnityEditor.Handles.DrawWireDisc(pos, Vector3.up, ToRun); UnityEditor.Handles.color = Color.yellow; UnityEditor.Handles.DrawWireDisc(pos, Vector3.up, ToTrot); if (Agent) { UnityEditor.Handles.color = Color.red; UnityEditor.Handles.DrawWireDisc(pos, Vector3.up, StoppingDistance); } } }
protected virtual void Swimming() { if (Stand) { return; //Skip if where doing nothing } RaycastHit WaterHitCenter; Pivots waterPivot = pivots[2]; //Gets the water Pivot //Front RayWater Cast if (Physics.Raycast(waterPivot.transform.position, -_transform.up, out WaterHitCenter, _Height * pivots[2].multiplier, LayerMask.GetMask("Water"))) { waterlevel = WaterHitCenter.point.y; //get the water level when find water isInWater = true; } else { isInWater = false; } if (isInWater) //if we hit water { if (!swim && (Pivot_Chest.Y < waterlevel) || (fall && !isJumping(0.5f, true))) { swim = true; _rigidbody.constraints = Still_Constraints; } //Stop swimming when he is coming out of the water //Just come out the water when hit the back ray else if (hit_Chest.distance < _Height && hit_Hip.distance < _Height + waterLine * 0.5f && !isJumping() && !fall && backray && swim) { swim = false; } } if (swim) { fall = false; isInAir = false; float angleWater = Vector3.Angle(_transform.up, WaterHitCenter.normal); Quaternion finalRot = Quaternion.FromToRotation(_transform.up, WaterHitCenter.normal) * _rigidbody.rotation; //Smoothy rotate until is Aling with the Water if (angleWater > 0.5f) { _transform.rotation = Quaternion.Lerp(_transform.rotation, finalRot, Time.deltaTime * 10); } else { _transform.rotation = finalRot; } //Smoothy Aling position with the Water Vector3 NewPos = new Vector3(_transform.position.x, waterlevel - _Height + waterLine, _transform.position.z); _transform.position = Vector3.Lerp(_transform.position, NewPos, Time.deltaTime * 10f); if (!isInWater) { swim = false; } } }