예제 #1
0
파일: AIPath.cs 프로젝트: puos/EAProjectV2
    //renders the path in orange
    public void OnDebugRender()
    {
        if (m_WayPoints.Count <= 0)
        {
            return;
        }

        int idx = 0;

        Vector3 wp = m_WayPoints[idx];

        Gizmos.color = Color.red;

        while (idx < m_WayPoints.Count - 1)
        {
            idx += 1;

            Vector3 n = m_WayPoints[idx];

            DebugExtension.DrawLineArrow2(wp, n, Color.black);

            wp = n;
        }

        if (m_bLooped)
        {
            DebugExtension.DrawLineArrow2(wp, m_WayPoints[0], Color.black);
        }

        Gizmos.DrawSphere(wp, 0.1f);

        Gizmos.color = Color.blue;

        Gizmos.DrawSphere(m_WayPoints[currentIdx], 0.1f);
    }
예제 #2
0
    private void OnDrawGizmosSelected()
    {
        Gizmos.color = Color.yellow;
        Gizmos.DrawSphere(posPuntero, 0.25f);

        if (m_pointList != null && m_pointList.Count > 1)
        {
            DebugExtension.DebugLine(m_pointList, Colors.LightBlue, Colors.DarkBlue);
        }

        //if (optimacedPointList != null && optimacedPointList.Count > 0)
        //    DebugExtension.DebugLine(optimacedPointList, Colors.Red, Colors.IndianRed);

        //if (normalizedPointList != null && normalizedPointList.Count > 0)
        //    DebugExtension.DebugLine(normalizedPointList, Colors.LightGreen, Colors.Green);

        //if (simplifyPointList != null && simplifyPointList.Count > 0)
        //{
        //    Vector2 vP = new Vector2(0, 0);
        //    for (int i = 0; i < simplifyPointList.Count; i++)
        //    {
        //        Debug.DrawLine(vP, simplifyPointList[i] + vP, Colors.Blue);
        //        vP = vP + simplifyPointList[i];
        //    }
        //}
    }
예제 #3
0
    void OnDrawGizmos()
    {
        if (grid == null)
        {
            DebugExtension.DebugLocalCube(transform, new Vector3(1, 1, 1));
        }
        else if (drawGrid)
        {
            Vector3 cellExtent = grid.GetCellExtent();
            Vector3 gridExtent = grid.GetExtent();
            Vector3 numCells   = new Vector3(grid.GetNumCells(0), grid.GetNumCells(1), grid.GetNumCells(2));
            Vector3 gridOrigin = grid.GetMinCorner();

            for (int i = 0; i < numCells.x; ++i)
            {
                for (int j = 0; j < numCells.y; ++j)
                {
                    for (int k = 0; k < numCells.z; ++k)
                    {
                        Gizmos.color = new Vector4(0.7f, 0.7f, 1, 0.2f);
                        Gizmos.DrawWireCube(gridOrigin + new Vector3(cellExtent.x * i + cellExtent.x / 2, cellExtent.y * j + cellExtent.y / 2, cellExtent.z * k + cellExtent.z / 2), cellExtent);
                    }
                }
            }
        }
    }
예제 #4
0
        private void OnDrawGizmosSelected()
        {
            // gravity opposite direction
            if (_enemyRigidbody != null)
            {
                Gizmos.color = Color.cyan;
                DrawArrow.ForGizmo(transform.position, _enemyRigidbody.velocity);
            }

            var targetNormal = (transform.position - Planet.position).normalized;
            var capsuleB     = Quaternion.FromToRotation(Vector3.up, targetNormal) *
                               CapsuleBegin;
            var capsuleE = Quaternion.FromToRotation(Vector3.up, targetNormal) *
                           CapsuleEnd;

            // bomb player detection range
            DebugExtension.DrawCapsule(transform.position + capsuleB,
                                       transform.position + capsuleE,
                                       _isPlayerInRange ? Color.red : Color.gray, CapsuleRadius);

            if (!_isPlayerInRange)
            {
                return;
            }

            Gizmos.color = Color.red;
            Gizmos.DrawLine(transform.position,
                            transform.position +
                            (Player.position - transform.position).normalized *
                            _distanceToPlayer);
        }
예제 #5
0
    /// <summary>
    ///     - Debugs a cone.
    /// </summary>
    /// <param name='position'>
    ///     - The position for the tip of the cone.
    /// </param>
    /// <param name='direction'>
    ///     - The direction for the cone gets wider in.
    /// </param>
    /// <param name='angle'>
    ///     - The angle of the cone.
    /// </param>
    /// <param name='color'>
    ///     - The color of the cone.
    /// </param>
    /// <param name='duration'>
    ///     - How long to draw the cone.
    /// </param>
    /// <param name='depthTest'>
    ///     - Whether or not the cone should be faded when behind other objects.
    /// </param>
    public static void DebugCone(Vector3 position, Vector3 direction, Color color, float angle = 45, float duration = 0, bool depthTest = true)
    {
        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);

        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);

        DebugExtension.DebugCircle(position + _forward, direction, color, (_forward - (slerpedVector.normalized * dist)).magnitude, duration, depthTest);
        DebugExtension.DebugCircle(position + (_forward * 0.5f), direction, color, ((_forward * 0.5f) - (slerpedVector.normalized * (dist * 0.5f))).magnitude, duration, depthTest);
    }
예제 #6
0
파일: Node.cs 프로젝트: flamit/AI-car
    void OnDrawGizmos()
    {
        frontTransform = transform.FindChild("front");
        backTransform  = transform.FindChild("back");

        Gizmos.color = new Vector4(0, 0, 1, 1);
        Gizmos.DrawWireSphere(transform.position, gizmoSize);

        Gizmos.color = new Vector4(0.7f, 0.7f, 1, 1);
        //Gizmos.DrawLine(transform.position, transform.position + transform.forward * frontWeight);
        //Gizmos.DrawLine(transform.position, transform.position - transform.forward * backWeight);

        Gizmos.DrawLine(transform.position, frontTransform.position);
        Gizmos.DrawLine(transform.position, backTransform.position);

        //Gizmos.DrawWireSphere(transform.position + transform.forward * frontWeight, gizmoSize / 2);
        //Gizmos.DrawWireSphere(transform.position - transform.forward * backWeight, gizmoSize / 2);

        DebugExtension.DrawArrow(transform.position, transform.forward / 2, Color.cyan);

        // up and right indicators
        Gizmos.color = new Vector4(1, 0, 0, 1);
        Gizmos.DrawLine(transform.position, transform.position + transform.right * 3);
        Gizmos.color = new Vector4(0, 1, 0, 1);
        Gizmos.DrawLine(transform.position, transform.position + transform.up * 3);
    }
예제 #7
0
    void DetectCollisions()
    {
        RaycastHit hit;
        Vector3    p1 = transform.position + Vector3.up * bottomOfCharacter;
        Vector3    p2 = p1 + Vector3.up * playerMovement.charController.height;

        for (int i = 0; i < 360; i += 18)
        {
            if (Physics.CapsuleCast(p1, p2, 0, new Vector3(Mathf.Cos(i), 0, Mathf.Sin(i)), out hit, playerMovement.charController.radius + collisionDetectionDistance))
            {
                PlayerModel tempPlay = null;
                tempPlay = hit.collider.gameObject.GetComponentInParent <PlayerModel>();
                if (tempPlay == null)
                {
                    Vector3 temp = (hit.point - transform.position).normalized;
                    temp.y = 0;
                    playerMovement.charController.Move((temp) * (collisionDetectionDistance - hit.distance));

                    if (hit.collider.gameObject.tag == "Hazard" && isHolding)
                    {
                        if (!playerPowerups.strengthPower)
                        {
                            Fail();
                        }
                    }
                }
            }
            DebugExtension.DebugCapsule(p1 + new Vector3(Mathf.Cos(i), 0, Mathf.Sin(i)), p2 + new Vector3(Mathf.Cos(i), 0, Mathf.Sin(i)), 0);
        }
    }
예제 #8
0
        protected override void Draw()
        {
            Gizmos.color = Color;

            if (Collider.edgeRadius == 0)
            {
                for (int i = 0; i < PointsLenght - 1; i++)
                {
                    Gizmos.DrawLine(MultipliedPoints[i], MultipliedPoints[i + 1]);
                }
            }
            else
            {
                float radius = Collider.edgeRadius;

                for (int i = 0; i < PointsLenght - 1; i++)
                {
                    Vector2 HelperVector = MultipliedPoints[i + 1] - MultipliedPoints[i];
                    HelperVector.Normalize();
                    HelperVector *= radius;

                    Gizmos.DrawLine(new Vector3(MultipliedPoints[i].x - HelperVector.y, MultipliedPoints[i].y + HelperVector.x), new Vector3(MultipliedPoints[i + 1].x - HelperVector.y, MultipliedPoints[i + 1].y + HelperVector.x));
                    Gizmos.DrawLine(new Vector3(MultipliedPoints[i].x + HelperVector.y, MultipliedPoints[i].y - HelperVector.x), new Vector3(MultipliedPoints[i + 1].x + HelperVector.y, MultipliedPoints[i + 1].y - HelperVector.x));

                    DebugExtension.DrawCircle(MultipliedPoints[i], Vector3.forward, Color, radius);
                }

                DebugExtension.DrawCircle(MultipliedPoints[PointsLenght - 1], Vector3.forward, Color, Collider.edgeRadius);
            }
        }
예제 #9
0
    public void Explode(float radius = 1.0f)
    {
        DebugExtension.DebugCircle(_piece.transform.position, Vector3.forward, Color.red, radius, 5);

        // Instancia o Sistema da Partículas
        Object.Instantiate(_explosion, _piece.transform.position, Quaternion.identity);

        // Checa se houve colisão em um raio ao redor da explosão
        var hits = Physics2D.CircleCastAll(_piece.transform.position, radius, Vector2.zero);

        foreach (var hit in hits)
        {
            var obj = hit.collider.GetComponent <IKillable>();
            if (obj != null && hit.collider.gameObject != _piece.gameObject)
            {
                var dir = (hit.collider.transform.position - _piece.transform.position).normalized;
                obj.TakeDamage(dir, 10);
            }

            var atk = hit.collider.GetComponent <IAttack>();
            if (atk != null)
            {
                Object.Destroy(hit.collider.gameObject);
            }
        }

        // ScreenShake
        Camera.main.GetComponent <CameraController>().Shake();
    }
 private void OnDrawGizmos()
 {
     if (groundCheck != null)
     {
         DebugExtension.DrawCircle(groundCheck.transform.position, Vector3.forward, Color.magenta, 0.2f);
     }
 }
예제 #11
0
    private void Update()
    {
        if (Grid == null)
        {
            BuildGrid();
        }

        if (DrawGridPoints)
        {
            foreach (var node in Grid.InnerGrid)
            {
                if (node.HasFlag(NodeFlags.Avoidance))
                {
                    DebugExtension.DebugWireSphere(Grid.ToWorldPosition(node.NavigableCenter), UnityColors.OrangeRed, 0.1f);
                }
                else if (node.HasFlag(NodeFlags.NearEdge))
                {
                    DebugExtension.DebugPoint(Grid.ToWorldPosition(node.NavigableCenter), UnityColors.Gray, 0.2f);
                }
                else if (node.HasFlag(NodeFlags.Navigation))
                {
                    DebugExtension.DebugPoint(Grid.ToWorldPosition(node.NavigableCenter), UnityColors.Blue, 0.2f);
                }
            }
        }
    }
예제 #12
0
    private void CheckIsGrounded()
    {
        Vector3 checkPosition =
            Vector3.down * boxCollider2D.size.y / 2 + transform.position;

        DebugExtension
        .DebugWireSphere(checkPosition,
                         Color.red,
                         fGroundSphereRadius,
                         Time.deltaTime);

        Collider2D[] colliders =
            Physics2D
            .OverlapCircleAll((Vector2)checkPosition,
                              fGroundSphereRadius,
                              groundMask);

        if (rb.velocity.y <= 0.0f)
        {
            if (colliders.Length > 0)
            {
                isGrounded = true;
            }
            else
            {
                isGrounded = false;
            }
        }
        else
        {
            isGrounded = false;
        }

        animator.SetBool("isJump", !isGrounded);
    }
예제 #13
0
    void OnDrawGizmos()
    {
        DebugExtension.DrawCircle(transform.position, transform.forward, Color.white, mRadius);

        DebugExtension.DrawCircle(transform.position + transform.right * mRadius, transform.up, Color.white, mThickness / 2);
        DebugExtension.DrawCircle(transform.position - transform.right * mRadius, transform.up, Color.white, mThickness / 2);

        DebugExtension.DrawCircle(transform.position + transform.up * mRadius, transform.right, Color.white, mThickness / 2);
        DebugExtension.DrawCircle(transform.position - transform.up * mRadius, transform.right, Color.white, mThickness / 2);

        Vector3 pos = transform.position + (transform.up * mRadius + transform.right * mRadius) / Mathf.Sqrt(2);

        DebugExtension.DrawCircle(pos, transform.up - transform.right, Color.white, mThickness / 2);

        pos = transform.position - (transform.up * mRadius + transform.right * mRadius) / Mathf.Sqrt(2);
        DebugExtension.DrawCircle(pos, transform.up - transform.right, Color.white, mThickness / 2);

        pos = transform.position + (transform.up * mRadius - transform.right * mRadius) / Mathf.Sqrt(2);
        DebugExtension.DrawCircle(pos, transform.up + transform.right, Color.white, mThickness / 2);

        pos = transform.position - (transform.up * mRadius - transform.right * mRadius) / Mathf.Sqrt(2);
        DebugExtension.DrawCircle(pos, transform.up + transform.right, Color.white, mThickness / 2);

        DebugExtension.DrawArrow(transform.position, transform.forward, Color.white);
    }
예제 #14
0
    /**
     * Check if Character is grounded by spherecasting the ground.
     */
    private bool CheckGrounding(out RaycastHit hitInfo)
    {
        float   gravSpeed = raycastOffset + (gravitySpeed + fallSpeedIncrementer) * Time.deltaTime;
        Vector3 position  = rb.position + new Vector3(0, raycastOffset, 0);

        DebugExtension.DebugArrow(position, -transform.up * gravSpeed);

        Boolean hitGround = Physics.Raycast(position, -transform.up,
                                            out hitInfo, gravSpeed, 1 | (1 << 10));

        if (hitGround)
        {
            if (hitInfo.collider.isTrigger)
            {
                return(false);
            }
            if (Vector3.Dot(hitInfo.normal, Vector3.up) > groundingAngle)
            {
                gravitySpeed      = GRAVITY * fallSpeed;
                currentJumpNumber = 0;
                IsJumping         = false;
                return(true);
            }
        }
        return(false);
    }
예제 #15
0
    private void Update()
    {
        foreach (Vector3 point in _points)
        {
            DebugExtension.DebugPoint(point);
        }
        ResetInput();

        if (Vector3.Distance(transform.position, target.position) > .5f)
        {
            Vector2        targetDir = target.position - transform.position;
            float          bestAngle = float.MaxValue; //TODO make smarter
            RegisteredMove bestMove  = null;
            foreach (var move in registeredMoves)
            {
                if (!move.checkCondition())
                {
                    continue;
                }
                float angle = Vector2.Angle(targetDir, move.direction);
                if (angle < bestAngle)
                {
                    bestAngle = angle;
                    bestMove  = move;
                }
            }
            bestMove?.doMove(bestMove.distanceToDuration(targetDir.magnitude));
            //print(bestMove?.name);
        }
    }
예제 #16
0
    public void DebugDrawVelocityGrid()
    {
        if (mVelGrid != null)
        {
            Vector3 cellExtent = mVelGrid.GetCellExtent();
            Vector3 gridExtent = mVelGrid.GetExtent();
            Vector3 numCells   = new Vector3(mVelGrid.GetNumCells(0), mVelGrid.GetNumCells(1), mVelGrid.GetNumCells(2));
            Vector3 gridOrigin = mVelGrid.GetMinCorner();

            for (int i = 0; i < numCells.x; ++i)
            {
                for (int j = 0; j < numCells.y; ++j)
                {
                    for (int k = 0; k < numCells.z; ++k)
                    {
                        uint[]  indices = { (uint)i, (uint)j, (uint)k };
                        uint    offset  = mVelGrid.OffsetFromIndices(indices);
                        Vector3 center  = mVelGrid.PositionFromIndices(indices) + cellExtent / 2;
                        if (mVelGrid[offset].v.magnitude == 0)
                        {
                            break;
                        }

                        Color color = new Vector4(0.8f, 0.8f, 1, 1);
                        DebugExtension.DrawArrow(center, mVelGrid[offset].v / 8, color);
                    }
                }
            }
        }
    }
    public void OnSceneGUI()
    {
        if (sim != null)
        {
            //debug particle index
            if (temp.debugParticleIndex)
            {
                for (int i = 0; i < sim.numberOfParticles(); i++)
                {
                    Vector2 pos = temp.transform.localToWorldMatrix.MultiplyPoint3x4(sim.getParticle(i).Position);
                    Handles.Label(pos, new GUIContent(i.ToString()));
                    DebugExtension.DebugPoint(pos, Color.blue, 2f);
                }
            }

            //debug spring index
            if (temp.debugSpringIndex)
            {
                for (int i = 0; i < sim.numberOfSprings(); i++)
                {
                    Vector2 midpt = (sim.getSpring(i).ParticleA.Position + sim.getSpring(i).ParticleB.Position) / 2f;
                    midpt = temp.transform.localToWorldMatrix.MultiplyPoint3x4(midpt);
                    GUIStyle st = new GUIStyle();
                    st.normal.textColor = Color.cyan - new Color(0f, 0f, 0f, 0.5f);
                    Handles.Label(midpt, new GUIContent(i.ToString()), st);
                }
            }
        }
    }
예제 #18
0
    void OnDrawGizmos()
    {
        var halfPlaneSizeX = transform.right * planeSize.x * 0.5f;
        var halfPlaneSizeY = transform.forward * planeSize.y * 0.5f;

        Debug.DrawLine(transform.position - halfPlaneSizeX - halfPlaneSizeY, transform.position + halfPlaneSizeX - halfPlaneSizeY, Color.green);
        Debug.DrawLine(transform.position + halfPlaneSizeX - halfPlaneSizeY, transform.position + halfPlaneSizeX + halfPlaneSizeY, Color.green);
        Debug.DrawLine(transform.position + halfPlaneSizeX + halfPlaneSizeY, transform.position - halfPlaneSizeX + halfPlaneSizeY, Color.green);
        Debug.DrawLine(transform.position - halfPlaneSizeX + halfPlaneSizeY, transform.position - halfPlaneSizeX - halfPlaneSizeY, Color.green);

        foreach (var particle in debugParticles)
        {
            if (particle.flags != 0)
            {
                DebugExtension.DebugCircle(new Vector3(particle.x, 0, particle.y), Color.magenta, particleRadius);
                DebugExtension.DrawArrow(new Vector3(particle.x, 0, particle.y), new Vector3(particle.dx, 0, particle.dy), Color.magenta);
                var currentPosition = particle.GetPosition(currentTime);
                DebugExtension.DebugCircle(new Vector3(currentPosition.x, 0, currentPosition.y), Color.blue, particleRadius);

                var proj = Project(new Vector3(currentPosition.x, 0, currentPosition.y));
                Debug.LogFormat("{0} {1}", proj.x * textureSize, proj.y * textureSize);

                break;
            }
        }
    }
예제 #19
0
 public void OFF()
 {
     isPose = false;
     DebugExtension.DrawCircle(transform.position, radius, Color.red, 3f);
     PauseScreen(false);
     SwitchBehaviour(false);
 }
예제 #20
0
        /// <summary>
        /// 爆破時の処理
        /// 周囲のコライダーを取得して四散させ、ダメージを与える
        /// 取得するコライダーはActorBaseがアタッチされたもの
        /// </summary>
        protected void AddExprForce()
        {
            DebugExtension.DrawCircle(transform.position, exprRadius, Color.green, 1f);

            //周囲のコライダー取得
            var targets = Physics2D.OverlapCircleAll(transform.position, exprRadius)
                          .Where(c =>
            {
                var component = c.GetComponent <ActorBase>();
                if (component == null)
                {
                    return(false);
                }
                return(component.HP > 0);
            })
                          .Select(c =>
            {
                Vector2 dir = c.transform.position - transform.position;
                return(new { col = c, direction = dir });
            });

            //吹き飛ばしとダメージを与える処理
            foreach (var target in targets)
            {
                AddForce(target.col, target.direction, exprPower);
                target.col.SendMessage("ExprDamaged");
            }
        }
예제 #21
0
    /// <summary>
    /// renvoi vrai ou faux si on a le droit de sauter (selon le hold)
    /// </summary>
    /// <returns></returns>
    public bool CanGrip(bool setupPoint = true)
    {
        //faux si le cooldown n'est pas fini, ou qu'on est pas grounded
        if (!coolDownGrip.IsReady() || !worldCollision.IsGroundedSafe())
        {
            return(false);
        }

        Collider coll;

        if (worldCollision.PlatformManager.IsGrippable(out coll))
        {
            if (!setupPoint)
            {
                return(true);
            }

            // The distance from the explosion position to the surface of the collider.
            //Collider coll = objectToAggrip.GetComponent<Collider>();
            pointAttract = coll.ClosestPointOnBounds(transform.position);
            DebugExtension.DebugWireSphere(pointAttract, 1, 1);
            return(true);
        }


        return(false);
    }
예제 #22
0
 private void OnDrawGizmosSelected()
 {
     if (_spawn != null)
     {
         DebugExtension.DrawArrow(_spawn.position, _spawn.forward * 0.2f, Color.red);
     }
 }
예제 #23
0
    /// <summary>
    ///     - Debugs a cylinder.
    /// </summary>
    /// <param name='start'>
    ///     - The position of one end of the cylinder.
    /// </param>
    /// <param name='end'>
    ///     - The position of the other end of the cylinder.
    /// </param>
    /// <param name='color'>
    ///     - The color of the cylinder.
    /// </param>
    /// <param name='radius'>
    ///     - The radius of the cylinder.
    /// </param>
    /// <param name='duration'>
    ///     - How long to draw the cylinder.
    /// </param>
    /// <param name='depthTest'>
    ///     - Whether or not the cylinder should be faded when behind other objects.
    /// </param>
    public static void DebugCylinder(Vector3 start, Vector3 end, Color color, float radius = 1, float duration = 0, bool depthTest = true)
    {
        Vector3 up      = (end - start).normalized * radius;
        Vector3 forward = Vector3.Slerp(up, -up, 0.5f);
        Vector3 right   = Vector3.Cross(up, forward).normalized *radius;

        //Radial circles
        DebugExtension.DebugCircle(start, up, color, radius, duration, depthTest);
        DebugExtension.DebugCircle(end, -up, color, radius, duration, depthTest);
        DebugExtension.DebugCircle((start + end) * 0.5f, up, color, radius, duration, depthTest);

        //Side lines
        Debug.DrawLine(start + right, end + right, color, duration, depthTest);
        Debug.DrawLine(start - right, end - right, color, duration, depthTest);

        Debug.DrawLine(start + forward, end + forward, color, duration, depthTest);
        Debug.DrawLine(start - forward, end - forward, color, duration, depthTest);

        //Start endcap
        Debug.DrawLine(start - right, start + right, color, duration, depthTest);
        Debug.DrawLine(start - forward, start + forward, color, duration, depthTest);

        //End endcap
        Debug.DrawLine(end - right, end + right, color, duration, depthTest);
        Debug.DrawLine(end - forward, end + forward, color, duration, depthTest);
    }
예제 #24
0
    public void Move(Vector2 velocityBias, bool isDash = false)
    {
//        DebugExtension.DebugArrow( BodyPosition, velocityBias, Color.blue );
//        DebugExtension.DebugArrow( BodyPosition, CurrentVelocity, Color.red );

        if (Time.deltaTime <= 0)
        {
            return;
        }

        var amount = (CurrentVelocity + velocityBias) * Time.deltaTime;

        var length = amount.magnitude;

        var direction = amount.normalized;

        var hit = Physics2D.CapsuleCast(BodyPosition, 0.6f * BodySize, CapsuleDirection2D.Vertical, 0, direction,
                                        length,
                                        _moveBlockingLayerMask | (isDash ? 0 : _dashableObstacleLayerMask));

        if (hit.collider != null && !transform.IsAncestorOf(hit.collider.transform))
        {
            DebugExtension.DebugPoint(hit.point, Color.yellow, 0.1f, 1);
            BodyPosition = hit.centroid;
            CancelHorizontalMovement();
        }
        else
        {
            transform.Translate(direction * length);
        }

        CheckWallCollisions(isDash);
    }
예제 #25
0
    //Wiresphere already exists

    /// <summary>
    ///     - Draws a cylinder.
    /// </summary>
    /// <param name='start'>
    ///     - The position of one end of the cylinder.
    /// </param>
    /// <param name='end'>
    ///     - The position of the other end of the cylinder.
    /// </param>
    /// <param name='radius'>
    ///     - The radius of the cylinder.
    /// </param>
    public static void DrawCylinder(Vector3 start, Vector3 end, float radius = 1.0f)
    {
        Vector3 up      = (end - start).normalized * radius;
        Vector3 forward = Vector3.Slerp(up, -up, 0.5f);
        Vector3 right   = Vector3.Cross(up, forward).normalized *radius;

        //Radial circles
        DebugExtension.DrawCircle(start, up, radius);
        DebugExtension.DrawCircle(end, -up, radius);
        DebugExtension.DrawCircle((start + end) * 0.5f, up, radius);

        //Side lines
        Gizmos.DrawLine(start + right, end + right);
        Gizmos.DrawLine(start - right, end - right);

        Gizmos.DrawLine(start + forward, end + forward);
        Gizmos.DrawLine(start - forward, end - forward);

        //Start endcap
        Gizmos.DrawLine(start - right, start + right);
        Gizmos.DrawLine(start - forward, start + forward);

        //End endcap
        Gizmos.DrawLine(end - right, end + right);
        Gizmos.DrawLine(end - forward, end + forward);
    }
예제 #26
0
    private void CheckWallCollisions(bool isDash = false)
    {
        var filter = _wallCollisionContactFilter2D;

        if (!isDash)
        {
            filter.layerMask |= _dashableObstacleLayerMask;
        }

        if (_collisionCheckCollider.OverlapCollider(filter, _wallColliders) > 0)
        {
            if (transform.IsAncestorOf(_wallColliders[0].transform))
            {
                return;
            }

            var distance2D = _collisionCheckCollider.Distance(_wallColliders[0]);
            DebugExtension.DebugPoint(distance2D.pointA, Color.red, 0.1f, 1);
            if (distance2D.distance > 0)
            {
//                Debug.LogError( "Should not be > 0" );
//                Debug.Log( string.Format( "{0} - {1}", distance2D.normal, distance2D.distance ) );
            }
            else
            {
                transform.Translate(distance2D.normal * distance2D.distance);
                CancelHorizontalMovement();
            }
        }
    }
예제 #27
0
        void OnTriggerEnter(Collider other)
        {
            if (!enabled || !_canGenerateCollisions || _checkedColliders.Contains(other))
            {
                return;
            }
            _checkedColliders.Add(other);
            var hitEntity = EntityController.GetEntity(UnityToEntityBridge.GetEntityId(other));
            var entity    = EntityController.GetEntity(EntityID);

            if (hitEntity == null || hitEntity.Id == EntityID)
            {
                return;
            }
            if (!CollisionCheckSystem.IsValidCollision(entity, _limitToEnemy, hitEntity, other, out var sourceNode, out var targetNode))
            {
                return;
            }
            var position  = transform.position;
            var hitPnt    = other.ClosestPointOnBounds(position);
            var hitNormal = (hitPnt - position).normalized;

#if DEBUG
            DebugExtension.DrawPoint(hitPnt, Color.yellow, 1.5f, 4f);
#endif
            hitEntity.Post(new CollisionEvent(entity, sourceNode, targetNode, hitPnt, hitNormal));
            entity.Post(new PerformedCollisionEvent(sourceNode, targetNode, hitPnt, hitNormal));
        }
    void OnDrawGizmosSelected()
    {
        Vector3 directionA = Vector3.zero;
        Vector3 directionB = Vector3.zero;

        //Calculer les deux vecteurs représentants l'angle de tir
        if (Application.isPlaying)
        {
            directionA = GeneralFunction.rotateVector(targetDirection.normalized, shootingAngle * Mathf.Deg2Rad);
            directionB = GeneralFunction.rotateVector(targetDirection.normalized, -shootingAngle * Mathf.Deg2Rad);
        }
        else
        {
            directionA = GeneralFunction.rotateVector(transform.forward, shootingAngle * Mathf.Deg2Rad);
            directionB = GeneralFunction.rotateVector(transform.forward, -shootingAngle * Mathf.Deg2Rad);
        }

        //Dessiner la portée de tir
        Gizmos.color = Color.yellow;
        DebugExtension.DrawCircle(transform.position, Vector3.up, Gizmos.color, shootingRange);

        //Dessiner l'angle de tir
        Gizmos.color = Color.gray;
        Gizmos.DrawRay(transform.position, directionA * detectionRange);
        Gizmos.DrawRay(transform.position, directionB * detectionRange);

        //Tracer un trait vers la cible
        if (targetPosition != Vector3.zero)
        {
            Gizmos.DrawLine(transform.position, targetPosition);
        }
    }
예제 #29
0
    public IEnumerator RequestNewPathTo(Vector2 pos)
    {
        DebugExtension.DebugCircle(pos, Vector3.forward, Color.blue, 0.2f);

        Vector2 cam = Camera.main.transform.position;

        if (pos.x == -1000)
        {
            bool found = false;
            while (!found)
            {
                Target = Camera.main.ViewportToWorldPoint(new Vector3(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), 0));
                if (!PathRequestManager.VerifyLocation(Target))
                {
                    Debug.Log("Não é possivel chegar à posição de destino");
                }
                else
                {
                    found = true;
                }
            }
        }
        else
        {
            Target = pos;
        }
        PathRequestManager.RequestPath(new PathRequest(transform.position, Target, OnPathFound));

        yield return(new WaitForEndOfFrame());
    }
예제 #30
0
        public static SteeringOutput GetSteering(KinematicState ownKS,
                                                 ref float targetOrientation,
                                                 float wanderRate   = 30f,
                                                 float wanderRadius = 10f, float wanderOffset = 20f)
        {
            // change target orientation (change location of surrogate target on unit circle)
            targetOrientation += wanderRate * Utils.binomial();

            // place surrogate target on circle of wanderRadius
            SURROGATE_TARGET.transform.position = Utils.OrientationToVector(targetOrientation) * wanderRadius;

            // place circle  "in front"
            SURROGATE_TARGET.transform.position += ownKS.position + Utils.OrientationToVector(ownKS.orientation) * wanderOffset;


            // show some gizmos before returning
            Debug.DrawLine(ownKS.position,
                           ownKS.position + Utils.OrientationToVector(ownKS.orientation) * wanderOffset,
                           Color.black);

            DebugExtension.DebugCircle(ownKS.position + Utils.OrientationToVector(ownKS.orientation) * wanderOffset,
                                       new Vector3(0, 0, 1),
                                       Color.red,
                                       wanderRadius);
            DebugExtension.DebugPoint(SURROGATE_TARGET.transform.position,
                                      Color.black,
                                      5f);



            // Seek the surrogate target
            return(Seek.GetSteering(ownKS, SURROGATE_TARGET));
        }