Beispiel #1
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();
    }
Beispiel #2
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());
    }
        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));
        }
Beispiel #4
0
 private void Update()
 {
     if (GameConstants.paused)
     {
         return;
     }
     this._elapsedTime += Time.deltaTime;
     if (!this._lostTrack)
     {
         if (this._elapsedTime >= this._lostTrackTime.Value)
         {
             this._elapsedTime -= this._lostTrackTime.Value;
             this._lostTrack    = true;
             this.SetWalkingSpeed();
             Helper.SpawnParticlesSystemOnTop(this._suspicionParticleSystemPrefab, this.gameObject);
         }
         return;
     }
     DebugExtension.DebugCircle(this._lastSeenPosition, Color.red, this._searchRadius.Value);
     if (this._elapsedTime >= this._searchTime.Value)
     {
         Helper.SpawnParticlesSystemOnTop(this._lostParticleSystemPrefab, this.gameObject);
         this._onStopSearch.Invoke();
         return;
     }
     this._changePositionElapsedTime += Time.deltaTime;
     if (this._changePositionElapsedTime >= this._changePositionTime.Value)
     {
         this._changePositionElapsedTime -= this._changePositionTime.Value;
         this._navMeshAgent.SetDestination(Helper.RandomNavSphere(this._lastSeenPosition, this._searchRadius.Value));
     }
 }
Beispiel #5
0
    private void Explode()
    {
        // Som
        SoundManager.Play("boom");

        DebugExtension.DebugCircle(transform.position, Vector3.forward, Color.red, _radius, 5);

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

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

        foreach (var hit in hits)
        {
            var obj = hit.collider.GetComponent <IKillable>();
            if (obj != null)
            {
                if (hit.collider.GetComponent <Enemy>() && _piece.GetComponent <Enemy>())
                {
                    continue;
                }

                var dir = (hit.collider.transform.position - transform.position).normalized;
                obj.TakeDamage(dir);
            }
        }

        // ScreenShake
        Camera.main.GetComponent <CameraController>().Shake();

        // Destroi
        Destroy(this.gameObject);
    }
Beispiel #6
0
    public void UpdateMemory(float dT)
    {
        //ToDo: for each known target, check line of sight: can we still see it?
        // if not, turn it into a memory (or forget it right away)
        //for each memory, increase timer and if too old, forget it
        for (int i = currentTargets.Count - 1; i >= 0; i--)
        {
            Target t = currentTargets[i];
            switch (t.type)
            {
            case TargetType.Enemy:
                if (t.actualTarget == null)
                {                        //doesn't exist. destroyed?
                                         //currentTargets.RemoveAt(i);
                    t.type  = TargetType.WasEnemy;
                    t.timer = 1;
                    DebugExtension.DebugCircle(t.lastKnownPos, 1, 10);
                    break;
                }
                {
                    RaycastHit hit;
                    Vector3    toTarget = (t.actualTarget.transform.position + Vector3.up * viewHeight) - (transform.position + Vector3.up * viewHeight);
                    Debug.DrawRay(transform.position + Vector3.up * viewHeight, toTarget, Color.grey);
                    bool hitSomething = Physics.Raycast(transform.position + Vector3.up * viewHeight, toTarget.normalized, out hit, toTarget.magnitude);
                    if (!hitSomething)
                    {                            //there's nothing there
                        //currentTargets.RemoveAt(i);
                        t.type  = TargetType.WasEnemy;
                        t.timer = 3;
                        DebugExtension.DebugCircle(t.lastKnownPos, 1, 10);
                    }
                    else
                    {
                        if (hit.collider.transform.IsChildOf(t.actualTarget.transform))
                        {                                //it's the same
                            t.lastKnownVel = Vector3.Lerp(t.lastKnownVel, (hit.collider.transform.position - t.lastKnownPos) / dT, 0.25f);
                            t.lastKnownPos = hit.collider.transform.position;
                        }
                        else
                        {                                //hit something else; can't see it
                            //currentTargets.RemoveAt(i);
                            t.type  = TargetType.WasEnemy;
                            t.timer = 10;                                       //investigate
                            DebugExtension.DebugCircle(t.lastKnownPos, 1, 10);
                        }
                    }
                }
                break;

            case TargetType.WasEnemy:
                t.timer -= dT;
                if (t.timer < 0)
                {
                    currentTargets.RemoveAt(i);
                    break;
                }
                break;
            }
        }
    }
Beispiel #7
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;
            }
        }
    }
Beispiel #8
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);
    }
Beispiel #9
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);
    }
Beispiel #10
0
        public static void OverlapSphere(Entity entity, Entity ignoreEntity, Vector3 position, float radius, bool limitEnemy)
        {
#if DEBUG_RAYCAST
            DebugExtension.DebugCircle(position, Color.red, radius, 2.5f);
#endif
            var limit = Physics.OverlapSphereNonAlloc(position, radius, _colliders, LayerMasks.DefaultCollision);
            CheckColliderList(entity, ignoreEntity, position, limit, limitEnemy);
        }
 // Update is called once per frame
 void Update()
 {
     //Gizmos.DrawSphere(sightStart.position, radius);
     //DebugExtension.DrawCircle(sightStart.position, Color.gray, radius);
     DebugExtension.DebugCircle(sightStart.position, sightStart.up, Color.gray, radius);
     Raycasting();
     Behaviors();
 }
Beispiel #12
0
        // Render the branch in unity editor for debug purpose
        // boundingCircleDepth = -1 means draw all of them
        public void DebugRender(Matrix4x4 localToWorld = default(Matrix4x4))
        {
            Vector2 thisPos;

            if (localToWorld != default(Matrix4x4))
            {
                thisPos = localToWorld.MultiplyPoint3x4(this.Position);
            }
            else
            {
                thisPos = this.Position;
            }

            //if (debugOn) DebugExtension.DebugPoint(thisPos,pointColor);


            //if it's not a leaf branch
            if (branchA != null || branchB != null)
            {
                Vector2 pos = (branchA == null) ? branchB.Position : branchA.Position;
                pos = (localToWorld == default(Matrix4x4)) ? pos : (Vector2)localToWorld.MultiplyPoint3x4(pos);

                Debug.DrawLine(thisPos, pos, branchColor);

                if (branchA != null)
                {
                    branchA.DebugRender(localToWorld);
                }
                if (branchB != null)
                {
                    branchB.DebugRender(localToWorld);
                }
            }
            //if it's a leaf branch
            else
            {
                Vector2 pos = new Vector2(GetChildrenBranchPosX, GetChildrenBranchPosY);
                pos = (localToWorld == default(Matrix4x4)) ? pos : (Vector2)localToWorld.MultiplyPoint3x4(pos);
                Debug.DrawLine(thisPos, pos, branchColor);
                if (BinaryTree.debugBranchLeaf)
                {
                    DebugExtension.DebugCircle(pos, Vector3.forward, leafColor, length / 10f);
                }
            }

            //debug bounding circle
            if (BinaryTree.debugBranchBoundingCircle)
            {
                if (boundingCircle.IsZero == false && (BinaryTree.debugBoundingCircleDepth == -1 || BinaryTree.debugBoundingCircleDepth == depth))
                {
                    Vector2 p = boundingCircle.position;
                    p = (localToWorld == default(Matrix4x4)) ? p : (Vector2)localToWorld.MultiplyPoint3x4(p);
                    DebugExtension.DebugCircle(p, Vector3.forward, boundingCircleColor, boundingCircle.radius);
                }
            }
        }
Beispiel #13
0
 // Update is called once per frame
 void Update()
 {
     DebugExtension.DebugPoint(debugPoint_Position, debugPoint_Color, debugPoint_Scale);
     DebugExtension.DebugBounds(new Bounds(new Vector3(10, 0, 0), debugBounds_Size), debugBounds_Color);
     DebugExtension.DebugCircle(new Vector3(20, 0, 0), debugCircle_Up, debugCircle_Color, debugCircle_Radius);
     DebugExtension.DebugWireSphere(new Vector3(30, 0, 0), debugWireSphere_Color, debugWireSphere_Radius);
     DebugExtension.DebugCylinder(new Vector3(40, 0, 0), debugCylinder_End, debugCylinder_Color, debugCylinder_Radius);
     DebugExtension.DebugCone(new Vector3(50, 0, 0), debugCone_Direction, debugCone_Color, debugCone_Angle);
     DebugExtension.DebugArrow(new Vector3(60, 0, 0), debugArrow_Direction, debugArrow_Color);
     DebugExtension.DebugCapsule(new Vector3(70, 0, 0), debugCapsule_End, debugCapsule_Color, debugCapsule_Radius);
 }
 // Update is called once per frame
 void Update()
 {
     foreach (Touch t in Input.touches)
     {
         if (t.phase == TouchPhase.Stationary || t.phase == TouchPhase.Ended)
         {
             continue;
         }
         Vector2 pos = Camera.main.ScreenToWorldPoint(t.position);
         DebugExtension.DebugCircle(pos, Vector3.forward, Color.red, 0.4f, 2);
     }
 }
Beispiel #15
0
    private void Update()
    {
        _direction.x = UltimateJoystick.GetHorizontalAxis("MoveRotate");
        _direction.z = UltimateJoystick.GetVerticalAxis("MoveRotate");

        DebugExtension.DebugCircle(_player.Transform.position, Color.red, _agroDistance);

        MovePlayer(Time.deltaTime);
        RotatePlayer(Time.deltaTime);
        MoveCamera(Time.deltaTime);
        RotateCamera();
    }
Beispiel #16
0
    void RenderParticle(Particle particle)
    {
        float    smoothingRadius  = sph.smoothingRadius;
        float    radius           = sph.radius;
        Particle selectedParticle = sph.selectedDebugParticle;

        Vector3 pos = particle.position;
        Vector3 dir = particle.velocity.normalized;

        DebugExtension.DebugArrow(pos, dir * radius, Color.white, 0, false);

        if (particle == selectedParticle)
        {
            DebugExtension.DebugCircle(pos, Vector3.forward, Color.red, radius, 0, false);
            foreach (Particle neighbor in sph.grid.GetNearby(particle))
            {
                DebugExtension.DebugCircle(neighbor.position, Vector3.forward, Color.magenta * 0.7f, radius * 1.5f, 0, false);
            }
        }
        else
        {
            DebugExtension.DebugCircle(pos, Vector3.forward, radius, 0, false);
        }



        Color radiusColor = new Color(0.5f, 0.5f, 0.5f, 0.4f);

        if (drawSmoothingRadius)
        {
            DebugExtension.DebugCircle(pos, Vector3.forward, radiusColor, smoothingRadius);
        }


        if (drawForce)
        {
            Color   forceColor = new Color(1.0f, 0, 0, 0.4f);
            Vector3 force3     = new Vector3(particle.force.x, particle.force.y, 0);
            DebugExtension.DebugArrow(pos, force3 * radius * 1f, forceColor);
        }


        // Vector3 ul = new Vector3 (offset.x, size.y + offset.y);
        // Vector3 ur = new Vector3 (size.x + offset.x, size.y + offset.y);
        // Vector3 dl = new Vector3 (offset.x, offset.y);
        // Vector3 dr = new Vector3 (size.x + offset.x, offset.y);

        // Debug.DrawLine (ul, ur, Color.grey);
        // Debug.DrawLine (ur, dr, Color.grey);
        // Debug.DrawLine (dr, dl, Color.grey);
        // Debug.DrawLine (dl, ul, Color.grey);
    }
Beispiel #17
0
    public void OnDebugUpdateRender()
    {
        if (m_vHeading.magnitude > 0)
        {
            DebugExtension.DebugArrow(m_vPos, m_vHeading * m_fBoundingRadius, Color.blue);
        }

        if (m_vSide.magnitude > 0)
        {
            DebugExtension.DebugArrow(m_vPos, m_vSide * m_fBoundingRadius, Color.red);
        }

        Gizmos.color = Color.black;

        DebugExtension.DebugCircle(m_vPos, m_fBoundingRadius);
    }
Beispiel #18
0
    void OnDrawGizmos()
    {
        var halfPlaneSize = planeSize * 0.5f;

        Debug.DrawLine(new Vector3(-halfPlaneSize.x, 0, -halfPlaneSize.y), new Vector3(+halfPlaneSize.x, 0, -halfPlaneSize.y), Color.green);
        Debug.DrawLine(new Vector3(+halfPlaneSize.x, 0, -halfPlaneSize.y), new Vector3(+halfPlaneSize.x, 0, +halfPlaneSize.y), Color.green);
        Debug.DrawLine(new Vector3(+halfPlaneSize.x, 0, +halfPlaneSize.y), new Vector3(-halfPlaneSize.x, 0, +halfPlaneSize.y), Color.green);
        Debug.DrawLine(new Vector3(-halfPlaneSize.x, 0, +halfPlaneSize.y), new Vector3(-halfPlaneSize.x, 0, -halfPlaneSize.y), Color.green);
        foreach (var particle in particles)
        {
            DebugExtension.DebugCircle(new Vector3(particle.birthPosition.x, 0, particle.birthPosition.y), new Color(1, 0, 1, 0.25f), particleRadius);
            DebugExtension.DrawArrow(new Vector3(particle.birthPosition.x, 0, particle.birthPosition.y), new Vector3(particle.direction.x, 0, particle.direction.y), new Color(1, 0, 1, 0.25f));
            var currentPosition = particle.GetPosition(currentTime);
            DebugExtension.DebugCircle(new Vector3(currentPosition.x, 0, currentPosition.y), new Color(0, 0, 1, 0.25f), particleRadius);
        }
    }
Beispiel #19
0
    public virtual void VisionRaycast()
    {
        DebugExtension.DebugCircle(visionCenter.position, Vector3.back, visionRadius, 0f, false);

        Vector2 origin = new Vector2(visionCenter.position.x, visionCenter.position.y);

        Collider2D col = Physics2D.CircleCast(origin, visionRadius, origin, 0.0f, 1 << LayerMask.NameToLayer(enemyLayer)).collider;


        if (col != null)
        {
            enemySeen = col.gameObject.GetComponent <Unit> ();
        }
        else
        {
            enemySeen = null;
        }
    }
Beispiel #20
0
    void OnCollisionEnter(Collision collision)
    {
        DebugExtension.DebugCircle(transform.position, Color.red, explosionRadius, 1);

        Collider[] colliders = Physics.OverlapSphere(transform.position, explosionRadius);
        for (int i = 0; i < colliders.Length; i++)
        {
            if (colliders[i] == safeCollider)
                continue;
            if(colliders[i].GetComponent<IDamagable>() != null)
            {
                Debug.Log(colliders[i]);
                colliders[i].GetComponent<IDamagable>().Damage();
            }
        }
        
        Destroy(gameObject);
    }
Beispiel #21
0
    // Update is called once per frame
    void Update()
    {
        if (targetValid)
        {
            // -- black line from US to the TARGET --
            Debug.DrawLine(transform.position, targetPos, Color.black);
            DebugExtension.DebugCircle(targetPos, Color.black, 3.0f);

            // -- setting the euler angle to rotate to --
            Vector3 euler = Quaternion.LookRotation(targetPos - transform.position).eulerAngles;
            //transform.rotation = Quaternion.Euler(new Vector3(0, euler.y, 0));

            currentTurnSpeed = Mathf.Clamp((euler.y - transform.rotation.eulerAngles.y), -turnSpeed, turnSpeed);

            // -- rotating towards the euler angle --
            transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(new Vector3(0, euler.y, 0)), turnSpeed * Time.deltaTime);
            //barrel.localRotation = Quaternion.Euler(new Vector3(euler.x, 0, 0));
        }
        else
        {
            currentTurnSpeed = 0;
        }

        //transform.rotation *= Quaternion.Euler(0, 0, -rotInput * turnSpeed * Time.deltaTime);
        //transform.rotation *= Quaternion.RotateTowards(transform.rotation, rotateToMouse, turnSpeed);

        //Debug.DrawRay(transform.position, mouseLocation*5, Color.red);

        // -- Firing --
        if (reloadTimer <= 0)
        {
            if (fireInput)
            {
                Shoot();
                Reload();
            }
        }
        else
        {
            reloadTimer -= Time.deltaTime;
        }

        UpdateAudio();
    }
Beispiel #22
0
    // Update is called once per frame
    void Update()
    {
        Vector3 direction = transform.TransformDirection(new Vector3(intPosition.x - transform.position.x, 0, cohe));

        if (debugArrow)
        {
            DebugExtension.DebugArrow(transform.position, direction, Color.blue);
            //DebugExtension.DrawCircle(transform.position,Vector3.up, Color.red, alig);
            DebugExtension.DebugCircle(transform.position, Vector3.up, Color.red, alig);
            DebugExtension.DebugPoint(transform.position + new Vector3(3 * transform.localScale.x / 2, -0.4f, 0), Color.yellow, 0.20f);
            DebugExtension.DebugPoint(transform.position + new Vector3(-3 * transform.localScale.x / 2, -0.4f, 0), Color.yellow, 0.20f);
        }
        GameObject[] allBoids;
        allBoids = GameObject.FindGameObjectsWithTag("Boids");

        for (int i = 0; i < allBoids.Length; i++)
        {
            Vector3        foceBoids = Vector3.zero;
            ref GameObject obj       = ref allBoids[i];
            if (obj.transform.position.z > transform.position.z && obj.transform.position.z < transform.position.z + alig && obj.GetComponent <Rigidbody>().velocity.magnitude < this.GetComponent <Rigidbody>().velocity.magnitude)
            {
                RaycastBoids rB     = obj.GetComponent <RaycastBoids>();
                raycastObj   objHit = rB.Raycast(widthObj);


                if (!objHit.right && transform.TransformDirection(objHit.ptRight - transform.position).x > 0)
                {
                    foceBoids = transform.TransformDirection(objHit.ptRight - transform.position);
                }

                if (!objHit.left && transform.TransformDirection(objHit.ptLeft - transform.position).x < 0)
                {
                    foceBoids = transform.TransformDirection(objHit.ptLeft - transform.position);
                }

                if (debugArrow)
                {
                    //Debug.LogWarning(" magnitude: " + foceBoids.magnitude);
                    DebugExtension.DebugArrow(transform.position, foceBoids.normalized, Color.cyan);
                }
            }

            direction += foceBoids * 10;
        }
Beispiel #23
0
    /// <summary>
    /// Draw some Debug helper shapes.</summary>
    void OnDrawGizmos()
    {
        Color color;

        if (Character.CurrentState is IdleState)
        {
            color = Color.green;
        }
        else if (Character.CurrentState is MoveState)
        {
            color = Color.blue;
        }
        else if (Character.CurrentState is AlertState)
        {
            color = Color.yellow;
        }
        else if (Character.CurrentState is ChaseState)
        {
            color = Color.magenta;
        }
        else if (Character.CurrentState is AttackState || Character.CurrentState is PlayerAttackState)
        {
            color = Color.red;
        }
        else if (Character.CurrentState is DefeatedState)
        {
            color = Color.black;
        }
        else
        {
            color = Color.grey;
        }
        // Draw a circle for sight range
        DebugExtension.DebugCircle(transform.position, color,
                                   (float)Math.Sqrt(Character.Stats.AlertnessRange.Value), 0);
        if (UnityEditor.EditorApplication.isPlaying)
        {
            DebugExtension.DebugCircle(transform.position, color,
                                       (float)Math.Sqrt(Character.AttackRange), 0);
        }
    }
Beispiel #24
0
    // Update is called once per frame
    void Update()
    {
        if (IsDebugEnabled)
        {
            DebugExtension.DebugCircle(transform.position, AttackRadius);
        }

        switch (ActionState)
        {
        case Action.Searching:
            var sqrDistance = (gameObject.transform.position - m_playerTransform.position).sqrMagnitude;
            if (sqrDistance < m_attackRadiusSqr)
            {
                ActionState = Action.Aim;
            }
            break;

        case Action.Aim:
            m_timer += Time.deltaTime;
            var lookPos = m_playerTransform.position - transform.position;
            if (LockY)
            {
                lookPos.y = 0;
            }
            var targetRotation = Quaternion.LookRotation(lookPos);
            transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * RotationDamping);
            if (m_timer >= AttackCoolDown)
            {
                m_timer     = 0.0f;
                ActionState = Action.Attack;
            }

            break;

        case Action.Attack:
            ObjectPooler.Instance.PoolObject(ObjectPooler.PooledElement.EnemyBulletStandard, gameObject, m_bulletSpawn.position);
            ActionState = Action.Searching;

            break;
        }
    }
Beispiel #25
0
    public static void DebugCollider(Collider2D hitbox)
    {
        var circleCollider2D = hitbox as CircleCollider2D;

        if (circleCollider2D != null)
        {
            var matrix = circleCollider2D.transform.localToWorldMatrix;
            DebugExtension.DebugCircle(matrix.MultiplyPoint3x4(circleCollider2D.offset), Vector3.forward, circleCollider2D.radius);
            return;
        }

        var boxCollider2D = hitbox as BoxCollider2D;

        if (boxCollider2D != null)
        {
            DebugExtension.DebugLocalCube(boxCollider2D.transform, boxCollider2D.size, boxCollider2D.offset);
            return;
        }

        throw new NotSupportedException(hitbox.GetType() + " not supported");
    }
    public virtual void OnDrawGizmos()
    {
        if (UnityEditor.EditorApplication.isPlaying)
        {
            Color oldColor = Gizmos.color;

            // Position
            Gizmos.color = DebugColor;
            Vector3 center = transform.position;
            Vector3 size   = new Vector3(1, 0.01f, 1);
            Gizmos.DrawCube(center, size);

            // AttackShape
            Gizmos.color = Color.red;
            foreach (AttackShapeMarker shape in AttackShape)
            {
                shape.Apply(transform);

                center = transform.position + transform.TransformVector(shape.Position);
                size   = new Vector3(1, 0.01f, 1);
                DebugExtension.DebugCircle(center, Gizmos.color, shape.Radius);

                float angle    = shape.Angle * Mathf.Rad2Deg;
                float rotation = (Mathf.PI / 180f) * (transform.eulerAngles.y - 90);
                Gizmos.DrawLine(center, center + shape.StartVector * shape.Radius);
                Gizmos.DrawLine(center, center + shape.EndVector * shape.Radius);

                // Forward
                Gizmos.DrawLine(center, center + shape.Forward * shape.Radius);
            }

            // AlertnessRadius
            DebugExtension.DebugCircle(transform.position, Gizmos.color, Stats.AlertnessRadius);

            // States
            DebugExtension.DebugCircle(transform.position, CurrentState.DebugColor, NavMeshAgent.radius);

            Gizmos.color = oldColor;
        }
    }
Beispiel #27
0
    /// <summary>
    ///     - Debugs a capsule.
    /// </summary>
    /// <param name='start'>
    ///     - The position of one end of the capsule.
    /// </param>
    /// <param name='end'>
    ///     - The position of the other end of the capsule.
    /// </param>
    /// <param name='color'>
    ///     - The color of the capsule.
    /// </param>
    /// <param name='radius'>
    ///     - The radius of the capsule.
    /// </param>
    /// <param name='duration'>
    ///     - How long to draw the capsule.
    /// </param>
    /// <param name='depthTest'>
    ///     - Whether or not the capsule should be faded when behind other objects.
    /// </param>
    public static void DebugCapsule(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;

        float   height     = (start - end).magnitude;
        float   sideLength = Mathf.Max(0, (height * 0.5f) - radius);
        Vector3 middle     = (end + start) * 0.5f;

        start = middle + ((start - middle).normalized * sideLength);
        end   = middle + ((end - middle).normalized * sideLength);

        //Radial circles
        DebugExtension.DebugCircle(start, up, color, radius, duration, depthTest);
        DebugExtension.DebugCircle(end, -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);

        for (int i = 1; i < 26; i++)
        {
            //Start endcap
            Debug.DrawLine(Vector3.Slerp(right, -up, i / 25.0f) + start, Vector3.Slerp(right, -up, (i - 1) / 25.0f) + start, color, duration, depthTest);
            Debug.DrawLine(Vector3.Slerp(-right, -up, i / 25.0f) + start, Vector3.Slerp(-right, -up, (i - 1) / 25.0f) + start, color, duration, depthTest);
            Debug.DrawLine(Vector3.Slerp(forward, -up, i / 25.0f) + start, Vector3.Slerp(forward, -up, (i - 1) / 25.0f) + start, color, duration, depthTest);
            Debug.DrawLine(Vector3.Slerp(-forward, -up, i / 25.0f) + start, Vector3.Slerp(-forward, -up, (i - 1) / 25.0f) + start, color, duration, depthTest);

            //End endcap
            Debug.DrawLine(Vector3.Slerp(right, up, i / 25.0f) + end, Vector3.Slerp(right, up, (i - 1) / 25.0f) + end, color, duration, depthTest);
            Debug.DrawLine(Vector3.Slerp(-right, up, i / 25.0f) + end, Vector3.Slerp(-right, up, (i - 1) / 25.0f) + end, color, duration, depthTest);
            Debug.DrawLine(Vector3.Slerp(forward, up, i / 25.0f) + end, Vector3.Slerp(forward, up, (i - 1) / 25.0f) + end, color, duration, depthTest);
            Debug.DrawLine(Vector3.Slerp(-forward, up, i / 25.0f) + end, Vector3.Slerp(-forward, up, (i - 1) / 25.0f) + end, color, duration, depthTest);
        }
    }
Beispiel #28
0
    // Use this for initialization
    void Start()
    {
        // Som
        SoundManager.Play("corte 2");
        SoundManager.Play("corte 1");

        _originalPosition = transform.position;
        if (special)
        {
            transform.localRotation = Quaternion.Euler(Vector3.up);
            StartCoroutine(CCannonBall_Trajectory_UP());
        }
        else
        {
            StartCoroutine(CCannonball_Trajectory());
        }

        explosion = Resources.Load <GameObject>("Field Objects/Explosion/Explosion");


        DebugExtension.DebugCircle(Destination, Vector3.forward, Color.magenta, 1, 1);



        RaycastHit2D[] hits = Physics2D.RaycastAll(transform.position, (Destination - (Vector2)transform.position).normalized, 20);
        foreach (RaycastHit2D hit in hits)
        {
            if (hit.collider.GetComponent <BossStopper>())
            {
                Destination = hit.point;
                pillarhit   = hit.collider.gameObject;
                hitpillar   = true;
            }
        }


        Destroy(this.gameObject, 5.0f);
    }
Beispiel #29
0
    // Update is called once per frame
    void Update()
    {
        // Casta um circulo ao redor

        if (_returning)
        {
            DebugExtension.DebugCircle(transform.position + Direction.xyz(transform.position), Vector3.forward, Color.red, 0.5f);

            var hits = Physics2D.CircleCastAll(transform.position + Direction.xyz(transform.position), 0.5f, Vector2.zero);
            foreach (var hit in hits)
            {
                if (hit.collider.GetComponent <IStopDash>() != null)
                {
                    Destroy(this.gameObject);
                }

                var obj = hit.collider.GetComponent <IKillable>();
                if (obj != null && _damage && hit.collider.GetComponent <BattlePiece>() != _piece)
                {
                    if (hit.collider.GetComponent <Enemy>() && _piece.GetComponent <Enemy>())
                    {
                        continue;
                    }

                    var dir = (Parent.position - transform.position).xy().normalized;

                    obj.TakeDamage(dir);
                    _damage = false;
                }
            }
        }


        // Atualiza o Line Renderer
        _line.SetPosition(0, Parent.position);
        _line.SetPosition(1, transform.position);
    }
Beispiel #30
0
    // Update is called once per frame
    void Update()
    {
        time += Time.deltaTime;

        // Checa colisões
        DebugExtension.DebugCircle(transform.position, Vector3.forward, Color.red, 0.5f);

        var hits = Physics2D.CircleCastAll(transform.position, 0.5f, Vector2.zero);

        foreach (var hit in hits)
        {
            if (hit.collider.GetComponent <IStopDash>() != null)
            {
                Destroy(this.gameObject);
            }

            var obj = hit.collider.GetComponent <IKillable>();
            if (obj != null && hit.collider.GetComponent <BattlePiece>() != _piece)
            {
                if (hit.collider.GetComponent <Enemy>() && _piece.GetComponent <Enemy>())
                {
                    continue;
                }

                var dir = hit.transform.position - transform.position;
                obj.TakeDamage(dir);

                Destroy(this.gameObject);
            }
        }


        if (time > StepTime) // Anda para o próximo lugar
        {
            Walk();
        }
    }