Esempio n. 1
0
    public override void OnActionReceived(float[] vectorAction)
    {
        float throttle = vectorAction[0];
        float rotate   = vectorAction[1];

        movement.Speed = vectorAction[0] / 2 + 0.5f;
        movement.Rotate(vectorAction[1] * 5);
    }
Esempio n. 2
0
    void DodgeWall(RaycastHit2D hit)
    {
        Vector2 position = new Vector2(transform.position.x, transform.position.y);

        var hitVector = hit.point - position;
        var angle     = -Vector2.SignedAngle(transform.up, hitVector);
        var random    = Random.value;

        if (wallSensors.HitPositions.Contains(WallPosition.LEFT) &&
            wallSensors.HitPositions.Contains(WallPosition.RIGHT) &&
            !wallSensors.HitPositions.Contains(WallPosition.MIDDLE))
        {
            // keep going forward
        }
        else if (hitVector.magnitude < 2f)
        {
            if ((random < 0.95 || closestShip != null))
            {
                movement.Rotate(Mathf.Sign(angle) * 2f);
            }
            else if (random >= 0.95 && random < 0.99 && closestShip == null)
            {
                movement.Rotate(Mathf.Sign(angle) * 50f);
            }
            else if (random >= 0.99 && closestShip == null)
            {
                movement.Rotate(Mathf.Sign(angle) * 80f);
            }
        }
    }
Esempio n. 3
0
    void DodgeWall(RaycastHit2D hit)
    {
        Vector2 position = new Vector2(transform.position.x, transform.position.y);

        var hitVector = hit.point - position;
        // Debug.Log($"Hit Vector: {hitVector}");
        var angle = -Vector2.SignedAngle(transform.up, hitVector);

        if (wallSensors.HitPositions.Contains(WallPosition.LEFT) &&
            wallSensors.HitPositions.Contains(WallPosition.RIGHT) &&
            !wallSensors.HitPositions.Contains(WallPosition.MIDDLE))
        {
            // keep going forward
        }
        else if (Random.value < 0.99)
        {
            movement.Rotate(Mathf.Sign(angle) * 2f);
        }
        else
        {
            movement.Rotate(Mathf.Sign(angle) * 90f);
        }
    }