Example #1
0
 protected void Start()
 {
     Pathfinder = GetComponent <Pathfinder>();
     Rigidbody  = GetComponent <Rigidbody2D>();
     Animator   = GetComponent <Animator>();
     WeaponUser = GetComponent <WeaponUser>();
 }
    protected override void Hit(Vector3 point, Vector3 normal)
    {
        this.transform.position = point;
        this.transform.rotation = Quaternion.LookRotation(normal);

        foreach (Renderer renderer in this.renderers)
        {
            renderer.enabled = false;
        }

        if (this.trailParticles != null)
        {
            this.trailParticles.Stop();
        }


        this.impactParticles.Play();

        Invoke("Cleanup", this.smokeTime);

        this.travelling = false;
        this.enabled    = false;

        WeaponUser.RegisterHit(point);
    }
Example #3
0
 private void Awake()
 {
     weaponUser = GetComponent <WeaponUser>();
     if (photonView.IsMine)
     {
         PlayerManager.instance.WeaponNetworking = this;
     }
 }
Example #4
0
    // Use this for initialization
    void Start()
    {
        rateOfFire        = baseRateOfFire;
        timeSinceLastShot = rateOfFire;
        timeSincePowerUp  = POWER_UP_DURATION_SECONDS;

        weaponUser  = weaponUserProvider.GetComponent <WeaponUser>();
        audioSource = gameObject.GetComponent <AudioSource>();
    }
Example #5
0
 private void Awake()
 {
     // get weaponUser component
     weaponUser = GetComponent <WeaponUser>();
     // Where ever the player starts, that is the starting position
     startingPosition = transform.position;
     // Calls the health component
     health = GetComponent <Health>();
     // Sets the singleton so the player can be accessed from anywhere
     Singleton = this;
 }
Example #6
0
    private void Start()
    {
        rb             = GetComponent <Rigidbody2D>();
        _animator      = GetComponent <Animator>();
        _weaponUser    = GetComponent <WeaponUser>();
        _interactibles = new List <Interactible>();
        _ui            = GameManager.Instance.hud;

        var state = PlayerState.Instance;

        if (state.hasCheckpoint)
        {
            transform.position = state.lastCheckpoint;
        }

        if (state.currentStateInvalid)
        {
            if (state.hasLevelStartState && !state.hasCheckpoint)
            {
                state.currentState = new CurrentPlayerState(state.enteredSaveState);
            }
            else
            {
                state.currentState = new CurrentPlayerState(state.lastSaveState);
            }
        }
        else if (state.currentState.primaryWeapon == null)
        {
            SetPrimary(defaultWeapon, defaultWeapon.startingAmmo, defaultWeapon.clipSize - defaultWeapon.startingAmmo);
            SetSecondary(null, 0, 0);
            #if !DEBUG
            state.currentState.maxHP = 6;
            #endif
        }

        // Now save level enter state
        state.hasLevelStartState = true;
        state.enteredSaveState   = new CurrentPlayerState(state.currentState);

        UpdateWeaponUI();

        state.hitpoints = state.currentState.maxHP;
        _ui.CreateHearts((int)Mathf.Ceil(state.currentState.maxHP * 0.5f));
        UpdateHealthUI();

        RespawnCompanions();

        _ui.gameObject.SetActive(true);

        GameManager.Instance.InitObjectiveCount();

        _normalMaterial = modelRenderer.material;
    }
Example #7
0
 // Called when the enemy starts
 void Awake()
 {
     // Get navmesh component
     navAgent = GetComponent <NavMeshAgent>();
     // Get weaponUser component
     weaponUser = GetComponent <WeaponUser>();
     // Finds all pickups in the game
     allPickups = GameObject.FindObjectsOfType <WeaponPickUp>();
     // Targets player singleton
     targetPlayer = Player.Singleton;
     // Gets health component
     health = GetComponent <Health>();
 }
Example #8
0
    private void Start()
    {
        _weaponUser = GetComponent <WeaponUser>();
        _hasWeapon  = _weaponUser != null;

        _initialPosition = transform.position;

        hitpoints = (int)(hitpoints * DifficultOwner.Instance.currentPreset.healthScale);

        base.Start();

        if (!excludeFromCounter && PlayerState.Instance.killedOverall.Contains(_initialPosition))
        {
            Destroy(gameObject);
        }
    }
    //float walkOffsetMagnitude = 0f;

    //float extraPitch = 0f;

    void Awake()
    {
        instance = this;

        this.fpCamera = Camera.main;

        this.fpCamera.fieldOfView = CAMERA_HIP_FOV;
        this.movementProbe        = this.transform.parent;
        this.positionSpring       = new Spring(POSITION_SPRING, POSITION_DRAG, -Vector3.one * MAX_POSITION_OFFSET, Vector3.one * MAX_POSITION_OFFSET, POSITION_SPRING_ITERAIONS);
        this.rotationSpring       = new Spring(ROTATION_SPRING, ROTATION_DRAG, -Vector3.one * MAX_ROTATION_OFFSET, Vector3.one * MAX_ROTATION_OFFSET, ROTATION_SPRING_ITERAIONS);
        this.weaponParent         = this.transform;
        //this.weaponParentOrigin = this.weaponParent.transform.localPosition;
        //this.fpCameraParent = this.fpCamera.transform.parent;

        this.movementProbe = this.transform;

        this.localOrigin  = this.transform.localPosition;
        this.lastPosition = this.movementProbe.position;
        this.lastRotation = this.movementProbe.eulerAngles;

        SetupHorizontalFov(90f);
        SetAimFov(CAMERA_AIM_FOV);
    }
Example #10
0
    private void FixedUpdate()
    {
        // Flash red if damaged
        if (_hitTimer > 0)
        {
            _hitTimer -= Time.deltaTime;
        }
        else
        {
            GetComponentInChildren <Renderer>().material.SetInt("IsHit", 0);
        }

        // Stuck checker
        if (_hasTarget && transform.position == _lastPos)
        {
            _stuckTimer += Time.deltaTime;
        }
        else
        {
            _stuckTimer = 0;
        }
        _lastPos = transform.position;

        // ===========
        // NEW ENEMY AI
        // ===========

        if (_hasTarget && _stuckTimer > 4f)
        {
            _hasTarget = false;
        }

        // Get an enemy target if we haven't already got a target
        if (!_hasTarget || _isWandering || !_targetIsPlayer)
        {
            // Check if we can see a target. (be it player or companion)
            var targets = Physics2D.OverlapCircleAll(transform.position, 5); // TODO: Variable for range

            var smallestDist = Single.MaxValue;
            foreach (var target in targets)
            {
                var dir   = target.transform.position - transform.position;
                var check = Physics2D.Raycast(transform.position, dir, dir.magnitude, solidLayer);

                if (check.collider == null)
                {
                    if (target.CompareTag("Player"))
                    {
                        var dist = (target.transform.position - transform.position).magnitude;
                        if (dist < smallestDist)
                        {
                            smallestDist     = dist;
                            _currentTarget   = target.transform.position;
                            _targetIsHostile = true;
                            _hasTarget       = true;
                            _targetHostile   = target;
                            _isWandering     = false;
                            _targetIsPlayer  = true;
                        }
                    }
                    if (target.CompareTag("Companion"))
                    {
                        var dist        = (target.transform.position - transform.position).magnitude;
                        var companionAI = target.GetComponent <CompanionAI>();
                        if (dist < smallestDist && companionAI.hitpoints > 0)
                        {
                            smallestDist     = dist;
                            _currentTarget   = target.transform.position;
                            _targetIsHostile = true;
                            _hasTarget       = true;
                            _targetHostile   = target;
                            _isWandering     = false;
                            _targetIsPlayer  = false;
                        }

                        if (companionAI.targetEnemy == gameObject)
                        {
                            _currentTarget   = target.transform.position;
                            _targetIsHostile = true;
                            _hasTarget       = true;
                            _targetHostile   = target;
                            _isWandering     = false;
                            _targetIsPlayer  = false;
                            break;
                        }
                    }
                }
            }
        }
        else if (_targetHostile == null)
        {
            _hasTarget      = false;
            _targetIsPlayer = false;
        }

        // Get direction vector
        var targetDir = _currentTarget - transform.position;

        if (_hasTarget)
        {
            if (targetDir.magnitude > 10)
            {
                _hasTarget      = false;
                _targetIsPlayer = false;
            }
        }

        if (_hasTarget)
        {
            // Check if we have line of sight of the target (if we have one)
            if (_targetIsHostile)
            {
                // If we can't see the target, we forget him
                var check = Physics2D.Raycast(transform.position, targetDir, targetDir.magnitude, solidLayer);

                if (check.collider == null)
                {
                    WeaponUser.PointGun(_targetHostile.transform.position, AnimationContoller(_targetHostile.transform.position));

                    // Update target
                    _currentTarget = _targetHostile.transform.position;
                    targetDir      = _currentTarget - transform.position;

                    if (_hasWeapon && targetDir.magnitude < attackRange)
                    {
                        _weaponUser.FirePrimary(Rigidbody, transform.position, targetDir.normalized);
                        return;
                    }
                }
                else
                {
                    _hasTarget       = false;
                    _targetIsHostile = false;
                    _isWandering     = false;
                    _targetIsPlayer  = false;
                }

                Animator.SetBool("Walking", _hasTarget);
            }
            else if (targetDir.magnitude < 0.5f)
            {
                _hasTarget       = false;
                _targetIsHostile = false;
                _isWandering     = false;
                _targetIsPlayer  = false;
            }

            // Move towards target
            _hasTarget = MoveTo(_currentTarget);
            AnimationContoller(_currentTarget);
            Animator.SetBool("Walking", _hasTarget);
        }
        else
        {
            _wanderTimer += Time.deltaTime;
            var r = new System.Random();
            if (_wanderTimer >= 1 && r.Next(0, 100) <= wanderChance)
            {
                // wanderChance% chance to move
                // Select a random cell within 2 positions, we have 4 tries before failing
                for (var i = 0; i < 4; i++)
                {
                    var x = r.Next(-2, 2);
                    var y = r.Next(-2, 2);

                    _currentTarget = transform.position + new Vector3(x, y, 0);
                    _hasTarget     = MoveTo(_currentTarget);
                    _isWandering   = _hasTarget;
                    Animator.SetBool("Walking", _hasTarget);
                    AnimationContoller(_currentTarget);
                    if (_hasTarget)
                    {
                        break;
                    }
                }

                // Reset timer
                _wanderTimer = 0;
            }
            else
            {
                Animator.SetBool("Walking", false);
            }
        }
    }
Example #11
0
    private void FixedUpdate()
    {
        // Get player
        var playerController = PlayerController.Instance;

        // Look for hostiles
        if (!_hasEnemy)
        {
            var   colliders        = Physics2D.OverlapCircleAll(transform.position, 5f);
            float smallestDistance = Single.MaxValue;
            foreach (var target in colliders)
            {
                if (target.CompareTag("Enemy"))
                {
                    var dist = (target.transform.position - transform.position).magnitude;
                    if (dist < smallestDistance)
                    {
                        smallestDistance = dist;
                        _currentEnemy    = target;
                        _hasEnemy        = true;
                        targetEnemy      = target.gameObject;
                    }
                }
            }
        }
        else if (_currentEnemy == null)
        {
            _hasEnemy   = false;
            targetEnemy = null;
        }

        if (_hasEnemy)
        {
            _patrol = false;

            // Line of sight
            var dir   = _currentEnemy.transform.position - transform.position;
            var check = Physics2D.Raycast(transform.position, dir.normalized, dir.magnitude, solidMask);

            if (check.collider == null)
            {
                WeaponUser.PointGun(_currentEnemy.transform.position, AnimationContoller(_currentEnemy.transform.position));

                if (dir.magnitude < 10f)
                {
                    // Check the player isnt in the way
                    var playerCheck = Physics2D.Raycast(transform.position, dir.normalized, dir.magnitude, playerMask);

                    if (playerCheck.collider == null && WeaponUser.FirePrimary(Rigidbody, transform.position, dir.normalized))
                    {
                        weaponRenderer.sprite = WeaponUser.primary.sprite;
                    }
                    Animator.SetBool("Walking", false);
                }
                else
                {
                    MoveTo(_currentEnemy.transform.position);
                    Animator.SetBool("Walking", true);
                }
            }
            else
            {
                _hasEnemy   = false;
                targetEnemy = null;
            }
        }

        if (!_hasEnemy)
        {
            var playerState = PlayerState.Instance;

            if (playerState.companionFollow)
            {
                _patrol = false;
                var dist = (playerController.transform.position - transform.position).magnitude;
                AnimationContoller(playerController.transform.position);
                WeaponUser.StopPointGun();
                if (dist > 1.5f)
                {
                    MoveTo(playerController.transform.position);
                    Animator.SetBool("Walking", true);
                }
                else
                {
                    Animator.SetBool("Walking", false);
                }
            }
            else if (_patrol)
            {
                _patrol = MoveTo(_patrolTarget);
                AnimationContoller(_patrolTarget);
                WeaponUser.StopPointGun();
                Animator.SetBool("Walking", true);
            }
            else
            {
                // Pick random destination
                _patrolTarget    = playerController.transform.position;
                _patrolTarget.x += UnityEngine.Random.Range(-3, 3);
                _patrolTarget.y += UnityEngine.Random.Range(-3, 3);
                _patrol          = MoveTo(_patrolTarget);
                AnimationContoller(_patrolTarget);
                WeaponUser.StopPointGun();
                Animator.SetBool("Walking", true);
            }

            // TP if far away
            if (!GameManager.Instance.bossBattle)
            {
                var d = (playerController.transform.position - transform.position).magnitude;
                if (d > 15)
                {
                    transform.position = playerController.transform.position;
                }
            }
        }
    }
 protected virtual void Hit(Vector3 point, Vector3 normal)
 {
     Destroy(this.gameObject);
     WeaponUser.RegisterHit(point);
 }