/// <summary> /// Draws a debug cross of the specified size and color at the specified point /// </summary> /// <param name="spot">Spot.</param> /// <param name="crossSize">Cross size.</param> /// <param name="color">Color.</param> public static void DebugDrawCross(Vector3 spot, float crossSize, Color color) { if (!DebugDrawEnabled) { return; } Vector3 tempOrigin = Vector3.zero; Vector3 tempDirection = Vector3.zero; tempOrigin.x = spot.x - crossSize / 2; tempOrigin.y = spot.y - crossSize / 2; tempOrigin.z = spot.z; tempDirection.x = 1; tempDirection.y = 1; tempDirection.z = 0; Debug.DrawRay(tempOrigin, tempDirection * crossSize, color); tempOrigin.x = spot.x - crossSize / 2; tempOrigin.y = spot.y + crossSize / 2; tempOrigin.z = spot.z; tempDirection.x = 1; tempDirection.y = -1; tempDirection.z = 0; Debug.DrawRay(tempOrigin, tempDirection * crossSize, color); }
protected void ShowNormals(Mesh normalMesh) { for (int i = 0; i < normalMesh.vertexCount; i++) { UDebug.DrawRay(normalMesh.vertices[i], normalMesh.normals[i] * 0.1f, Color.red); } }
/// <summary> /// Draws the arrow end for DebugDrawArrow /// </summary> /// <param name="drawGizmos">If set to <c>true</c> draw gizmos.</param> /// <param name="arrowEndPosition">Arrow end position.</param> /// <param name="direction">Direction.</param> /// <param name="color">Color.</param> /// <param name="arrowHeadLength">Arrow head length.</param> /// <param name="arrowHeadAngle">Arrow head angle.</param> private static void DrawArrowEnd(bool drawGizmos, Vector3 arrowEndPosition, Vector3 direction, Color color, float arrowHeadLength = 0.25f, float arrowHeadAngle = 40.0f) { if (!DebugDrawEnabled) { return; } if (direction == Vector3.zero) { return; } Vector3 right = Quaternion.LookRotation(direction) * Quaternion.Euler(arrowHeadAngle, 0, 0) * Vector3.back; Vector3 left = Quaternion.LookRotation(direction) * Quaternion.Euler(-arrowHeadAngle, 0, 0) * Vector3.back; Vector3 up = Quaternion.LookRotation(direction) * Quaternion.Euler(0, arrowHeadAngle, 0) * Vector3.back; Vector3 down = Quaternion.LookRotation(direction) * Quaternion.Euler(0, -arrowHeadAngle, 0) * Vector3.back; if (drawGizmos) { Gizmos.color = color; Gizmos.DrawRay(arrowEndPosition + direction, right * arrowHeadLength); Gizmos.DrawRay(arrowEndPosition + direction, left * arrowHeadLength); Gizmos.DrawRay(arrowEndPosition + direction, up * arrowHeadLength); Gizmos.DrawRay(arrowEndPosition + direction, down * arrowHeadLength); } else { Debug.DrawRay(arrowEndPosition + direction, right * arrowHeadLength, color); Debug.DrawRay(arrowEndPosition + direction, left * arrowHeadLength, color); Debug.DrawRay(arrowEndPosition + direction, up * arrowHeadLength, color); Debug.DrawRay(arrowEndPosition + direction, down * arrowHeadLength, color); } }
private void MoveUpdate() { #if UNITY_EDITOR _animator.SetFloat(_setup.MoveMultiplierParamName, _setup.MoveAnimSpeed); #endif // TODO FRS 161115 Ahora mismo deja al boomon encajonado al primer contacto, pero seguir investigando //if ((_controller.collisionFlags & CollisionFlags.Sides) != 0) //{ // CurrentState = State.Idle; // return; //} if (_controller.isGrounded || Physics.Raycast(transform.position, -_refSystem.Up, _setup.FallHeightMin)) { _controller.SimpleMove(_velocity); Debug.DrawRay(transform.position, -_setup.FallHeightMin * _refSystem.Up, Color.green); } else { Throw(_velocity); Debug.DrawRay(transform.position, -_setup.FallHeightMin * _refSystem.Up, Color.red); } }
private string GetHitTag() { //TODO: rethink this someday if (canDrawDebug) { Debug.DrawRay(transform.position, Vector3.forward * 2, Color.green, 2.0f); } if (!Physics.Raycast(transform.position, Vector3.forward, out var hitRes)) { return(null); } if (hitRes.transform.CompareTag("MetallicBarrier")) { return("MetallicBarrier"); } if (hitRes.transform.CompareTag("RedBarrier")) { return("RedBarrier"); } if (hitRes.transform.CompareTag("JumpBooster")) { return("JumpBooster"); } if (hitRes.transform.CompareTag("JumpBoosterCenter")) { return("JumpBoosterCenter"); } return(null); }
private bool IsGrounded() { float extraHeightText = 0.1f; RaycastHit2D raycastHit = Physics2D.BoxCast(_boxCollider2.bounds.center, _boxCollider2.bounds.size, 0f, Vector2.down, extraHeightText, 1 << 8); Color rayColor; if (raycastHit.collider != null) { rayColor = Color.green; } else { rayColor = Color.red; } Debug.DrawRay(_boxCollider2.bounds.center + new Vector3(_boxCollider2.bounds.extents.x, 0), Vector2.down * (_boxCollider2.bounds.extents.y + extraHeightText), rayColor); Debug.DrawRay(_boxCollider2.bounds.center - new Vector3(_boxCollider2.bounds.extents.x, 0), Vector2.down * (_boxCollider2.bounds.extents.y + extraHeightText), rayColor); Debug.DrawRay( _boxCollider2.bounds.center - new Vector3(_boxCollider2.bounds.extents.x, _boxCollider2.bounds.extents.y + extraHeightText), Vector2.right * (_boxCollider2.bounds.extents.x * 2f), rayColor); return(raycastHit.collider != null); }
public static void DrawCone(Vector3 position, Vector3 direction, Color color = default, float angle = 45, float duration = 0, bool depthTest = true) { /// Debug Extension /// By Arkham Interactive /// Source: https://assetstore.unity.com/packages/tools/debug-drawing-extension-11396 /// - Static class that extends Unity's debugging functionallity. /// - Attempts to mimic Unity's existing debugging behaviour for ease-of-use. /// - Includes gizmo drawing methods for less memory-intensive debug visualization. float length = direction.magnitude; Vector3 _forward = direction; Vector3 _up = Vector3.Slerp(_forward, -_forward, 0.5f); Vector3 _right = Vector3.Cross(_forward, _up).normalized *length; direction = direction.normalized; Vector3 slerpedVector = Vector3.Slerp(_forward, _up, angle / 90.0f); float dist; var farPlane = new Plane(-direction, position + _forward); var distRay = new Ray(position, slerpedVector); farPlane.Raycast(distRay, out dist); color = color != default ? color : Color.white; Debug.DrawRay(position, slerpedVector.normalized * dist, color); Debug.DrawRay(position, Vector3.Slerp(_forward, -_up, angle / 90.0f).normalized *dist, color, duration, depthTest); Debug.DrawRay(position, Vector3.Slerp(_forward, _right, angle / 90.0f).normalized *dist, color, duration, depthTest); Debug.DrawRay(position, Vector3.Slerp(_forward, -_right, angle / 90.0f).normalized *dist, color, duration, depthTest); DrawCircle(position + _forward, direction, (_forward - (slerpedVector.normalized * dist)).magnitude, color, duration, depthTest); DrawCircle(position + (_forward * 0.5f), direction, ((_forward * 0.5f) - (slerpedVector.normalized * (dist * 0.5f))).magnitude, color, duration, depthTest); }
public static void DrawRay(Vector3 from, Vector3 dist, Color c, float duration = 0.0f) { if (!showDebugging) { return; } Debug.DrawRay(from, dist, c, duration); }
/// <summary> /// Draws a debug ray in 2D and does the actual raycast /// </summary> /// <returns>The raycast hit.</returns> /// <param name="rayOriginPoint">Ray origin point.</param> /// <param name="rayDirection">Ray direction.</param> /// <param name="rayDistance">Ray distance.</param> /// <param name="mask">Mask.</param> /// <param name="debug">If set to <c>true</c> debug.</param> /// <param name="color">Color.</param> public static RaycastHit2D RayCast(Vector2 rayOriginPoint, Vector2 rayDirection, float rayDistance, LayerMask mask, Color color, bool drawGizmo = false) { if (drawGizmo && DebugDrawEnabled) { Debug.DrawRay(rayOriginPoint, rayDirection * rayDistance, color); } return(Physics2D.Raycast(rayOriginPoint, rayDirection, rayDistance, mask)); }
private void Update() { SetInputs(); //Temp transformPosition = Motor.transform.position; playerMaxStableMoveSpeed = player.MaxStableMoveSpeed; _playerIsCrouching = player._isCrouching; Debug.DrawRay(Motor.transform.position, storedDeviationDir, Color.red); }
public static void DrawArrow(Vector3 pos, Vector3 direction, Color color, float arrowHeadLength = 0.25f, float arrowHeadAngle = 20.0f) { Debug.DrawRay(pos, direction, color); Vector3 right = Quaternion.LookRotation(direction) * Quaternion.Euler(0, 180 + arrowHeadAngle, 0) * new Vector3(0, 0, 1); Vector3 left = Quaternion.LookRotation(direction) * Quaternion.Euler(0, 180 - arrowHeadAngle, 0) * new Vector3(0, 0, 1); Debug.DrawRay(pos + direction, right * arrowHeadLength, color); Debug.DrawRay(pos + direction, left * arrowHeadLength, color); }
private void CheckIsGrounded() { RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down, distanceToGround + 0.1f, collisionMask); Debug.DrawRay(transform.position, Vector2.down * (distanceToGround + 0.1f), Color.red); if (IsGrounded != hit) { IsGrounded = hit; } }
/// <summary> /// Draws a debug arrow going from the origin position and along the direction Vector3 /// </summary> /// <param name="origin">Origin.</param> /// <param name="direction">Direction.</param> /// <param name="color">Color.</param> /// <param name="arrowLength">Arrow length.</param> /// <param name="arrowHeadLength">Arrow head length.</param> /// <param name="arrowHeadAngle">Arrow head angle.</param> public static void DebugDrawArrow(Vector3 origin, Vector3 direction, Color color, float arrowLength, float arrowHeadLength = 0.20f, float arrowHeadAngle = 35.0f) { if (!DebugDrawEnabled) { return; } Debug.DrawRay(origin, direction * arrowLength, color); DrawArrowEnd(false, origin, direction * arrowLength, color, arrowHeadLength, arrowHeadAngle); }
/// <summary> /// Draws a debug ray in 3D and does the actual raycast /// </summary> /// <returns>The raycast hit.</returns> /// <param name="rayOriginPoint">Ray origin point.</param> /// <param name="rayDirection">Ray direction.</param> /// <param name="rayDistance">Ray distance.</param> /// <param name="mask">Mask.</param> /// <param name="debug">If set to <c>true</c> debug.</param> /// <param name="color">Color.</param> /// <param name="drawGizmo">If set to <c>true</c> draw gizmo.</param> public static RaycastHit Raycast3D(Vector3 rayOriginPoint, Vector3 rayDirection, float rayDistance, LayerMask mask, Color color, bool drawGizmo = false) { if (drawGizmo && DebugDrawEnabled) { Debug.DrawRay(rayOriginPoint, rayDirection * rayDistance, color); } RaycastHit hit; Physics.Raycast(rayOriginPoint, rayDirection, out hit, rayDistance, mask); return(hit); }
public static void DrawArrow(Vector3 position, Vector3 direction, Color?color = null, float duration = 0, bool depthTest = true) { /// Debug Extension /// By Arkham Interactive /// Source: https://assetstore.unity.com/packages/tools/debug-drawing-extension-11396 /// - Static class that extends Unity's debugging functionallity. /// - Attempts to mimic Unity's existing debugging behaviour for ease-of-use. /// - Includes gizmo drawing methods for less memory-intensive debug visualization. Debug.DrawRay(position, direction, color ?? DefaultColor, duration, depthTest); DrawCone(position + direction, -direction * 0.333f, color ?? DefaultColor, 15, duration, depthTest); }
private bool FireRaycasts(IStateMachine stateMachine) { var agentEyes = stateMachine.GetAgent().GetEyes(); var agentStats = stateMachine.GetAgent().GetStats(); for (var i = 0; i < 5; i++) { RaycastHit hit; Vector3 rayDirection; switch (i) { case 0: rayDirection = agentEyes.transform.forward - agentEyes.right; break; case 1: rayDirection = (agentEyes.transform.forward - agentEyes.right / 2); break; case 2: rayDirection = agentEyes.transform.forward; break; case 3: rayDirection = (agentEyes.transform.forward + agentEyes.right / 2); break; case 4: rayDirection = agentEyes.transform.forward + agentEyes.right; break; default: rayDirection = new Vector3(); break; } Debug.DrawRay(agentEyes.transform.position, rayDirection * agentStats.ViewDistance, stateMachine.GetCurrentState().GetCurrentStateColor()); var layerMask = 1 << 10; // invert bitmask to collide with all layers except 10 layerMask = ~layerMask; if (Physics.Raycast(agentEyes.transform.position, rayDirection, out hit, agentStats.ViewDistance, layerMask) && hit.collider.CompareTag("agent")) { stateMachine.GetAgent().Target = hit.transform; return(true); } } return(false); }
/// <summary> /// Draws a debug ray without allocating memory /// </summary> /// <returns>The ray cast non alloc.</returns> /// <param name="array">Array.</param> /// <param name="rayOriginPoint">Ray origin point.</param> /// <param name="rayDirection">Ray direction.</param> /// <param name="rayDistance">Ray distance.</param> /// <param name="mask">Mask.</param> /// <param name="color">Color.</param> /// <param name="drawGizmo">If set to <c>true</c> draw gizmo.</param> public static RaycastHit2D MonoRayCastNonAlloc(RaycastHit2D[] array, Vector2 rayOriginPoint, Vector2 rayDirection, float rayDistance, LayerMask mask, Color color, bool drawGizmo = false) { if (drawGizmo && DebugDrawEnabled) { Debug.DrawRay(rayOriginPoint, rayDirection * rayDistance, color); } if (Physics2D.RaycastNonAlloc(rayOriginPoint, rayDirection, array, rayDistance, mask) > 0) { return(array[0]); } return(new RaycastHit2D()); }
private void TouchBegan(Vector3 position) { var ray = Camera.main.ScreenPointToRay(position); Debug.DrawRay(ray.origin, ray.direction, Color.green); Debug.Log("origin:"+ray.origin); Debug.Log("direction:" + ray.direction); var hit = new RaycastHit(); if (Physics.Raycast(ray, out hit, rayDistance)) { hit.collider.gameObject.GetComponent<Cube>()?.TapHold(ref hit); } }
public static void DrawPoint(Vector3 position, Color color = default, float scale = 1.0f, float duration = 0, bool depthTest = true) { /// Debug Extension /// By Arkham Interactive /// Source: https://assetstore.unity.com/packages/tools/debug-drawing-extension-11396 /// - Static class that extends Unity's debugging functionallity. /// - Attempts to mimic Unity's existing debugging behaviour for ease-of-use. /// - Includes gizmo drawing methods for less memory-intensive debug visualization. color = (color != default) ? color : DefaultColor; Debug.DrawRay(position + (Vector3.up * (scale * 0.25f)), -Vector3.up * scale * 0.5f, color, duration, depthTest); Debug.DrawRay(position + (Vector3.right * (scale * 0.25f)), -Vector3.right * scale * 0.5f, color, duration, depthTest); Debug.DrawRay(position + (Vector3.forward * (scale * 0.25f)), -Vector3.forward * scale * 0.5f, color, duration, depthTest); }
private void DrawLines() { var position = childrenPosition; position.y = -0.20f; var right = transform.right; Debug.DrawRay(position, right, Color.red, 1f); Debug.DrawRay(position, -right, Color.red, 1f); var forward = transform.forward; Debug.DrawRay(position, forward, Color.red, 1f); Debug.DrawRay(position, -forward, Color.red, 1f); }
private bool IsGrounded() { float extraHeight = 0.02f; Bounds colliderBounds = _collider.bounds; Vector2 origin = new Vector2(colliderBounds.center.x - colliderBounds.extents.x, colliderBounds.center.y - (colliderBounds.extents.y + extraHeight)); float distance = colliderBounds.size.x; RaycastHit2D hit = Physics2D.Raycast(origin, Vector2.right, distance, groundLayers); Color color; color = hit.collider != null ? Color.green : Color.red; Debug.DrawRay(origin, Vector2.right * distance, color); return(hit.collider != null); }
private bool DecideJump() { //Positive (Moves Right) Vector3 spawn = (transform.position + GetComponent <CapsuleCollider>().center); //Shoots the Raycasts bool hit1Hit = Physics.Raycast(spawn + (RightDirection * 0.5f), Vector3.down, 5, Move.layerMask); bool hit2Hit = Physics.Raycast(spawn + (RightDirection * PitLength), Vector3.down, 5, Move.layerMask); //Should Jump if (!hit1Hit && hit2Hit) { return(true); } Debug.DrawRay(spawn + (RightDirection * PitLength * Horizontal), Vector3.down, Color.red); Debug.DrawRay(spawn + (RightDirection * 0.5f * Horizontal), Vector3.down, Color.red); return(false); }
float Eye6() { RaycastHit intersect; Quaternion q = Quaternion.AngleAxis(direction[5], Vector3.up); Vector3 offset = new Vector3(0, 0, 0); if (Physics.Raycast(transform.position + offset, q * transform.forward, out intersect, magnitude[5])) { //Debug.Log("LEFT RAY WAS HIT"); Debug.DrawRay(transform.position + offset, q * transform.forward * intersect.distance, Color.red); //script.movedir++; //Debug.Log("Left eye sees something "+intersect.distance+" meters away!"); return(intersect.distance); } else { //Debug.DrawRay(transform.position+offset,q * transform.forward * intersect,Color.green); return(0); } }
//壁があるない void RayObject() { Ray ray = new Ray(transform.position, transform.up); RaycastHit hit; float a = 1000; for (int i = 0; i < 3; i++) { ray = new Ray(transform.position + Vector3.right * (i - 1) * 2.0f, transform.up); Debug.DrawRay(transform.position + Vector3.right * 2.0f * (i - 1), transform.up * rayline, Color.red, 0, true); //レイの判定(飛ばすレイ、レイが当たったものの情報、レイの長さ) if (Physics.Raycast(ray, out hit, rayline)) //壁がある時 { Physics.queriesHitTriggers = false; //こいつでトリガーのやつは無視するぽい if (hit.collider.tag == "Wall") { rayFlag = true; ob.SetActive(true); //令の長さを取得 float dis = Vector3.Distance(hit.point, transform.position + Vector3.right * 2.0f * (i - 1)); if (a > dis) { a = dis; //ヒットしてる位置を取得 hitPoint = hit.point; //オブジェクトを取得 hitObject = hit.collider.gameObject; } } } else //壁がない時 { rayFlag = false; ob.SetActive(false); } } test(); }
public void Shoot(float weaponRange, Transform origin) { Vector3 fwd = origin.transform.TransformDirection(Vector3.forward); Debug.DrawRay(origin.transform.position, fwd * weaponRange, Color.green, 2); RaycastHit hit; if (Physics.Raycast(origin.transform.position, fwd, out hit, weaponRange)) { GameObject obj = hit.transform.gameObject; Debug.Log(obj.name); switch (obj.tag) { case "Enemy": var id = obj.GetComponent <OtherPlayer>().id; PlayerEventChannel.SendEvent(PlayerEvent.Hit(id)); return; } PlayerEventChannel.SendEvent(PlayerEvent.Shoot()); } }
// Virtual just if at any case we want to override thie per weapon. protected virtual void Fire() { if (ammo > 0) { if (!openFireParticles.isPlaying) { openFireParticles.Play(); } //fire ray from center of the screen ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f)); Debug.DrawRay(ray.origin, ray.direction, Color.green, 5); if (Physics.Raycast(ray, out hit, 20, layer_mask)) { Debug.Log(hit.collider.gameObject.name); hit.collider.gameObject.GetComponent <Enemy>().ReceiveDamage(damage); playerHUD.playerHUD.CrossHair.color = Color.red; } else { playerHUD.playerHUD.CrossHair.color = Color.white; } ammo--; playerHUD.UpdatePlayerHUD(); } else { if (!isReloading) { Debug.Log("Reload please"); //TODO Adding UI openFireParticles.Stop(); StartCoroutine(Reload()); } } }
public static void DrawRay(Vector3 start, Vector3 direction, Color color, float duration, bool depthTest) { Debug.DrawRay(start, direction, color, duration, depthTest); }
public static void DrawRay(Vector3 start, Vector3 direction, Color color, float duration) { Debug.DrawRay(start, direction, color, duration); }
public static void DrawRay(Vector3 start, Vector3 direction, Color color) { Debug.DrawRay(start, direction, color); }
public static void DrawRay(Vector3 start, Vector3 direction) { Debug.DrawRay(start, direction); }