Exemple #1
0
 private void OnCollisionEnter(Collision other)
 {
     // TODO: fix jumping while next to charging enemies
     Debug.Log("We hit something bro...");
     if (other.collider.gameObject.isStatic)
     {
         ContactPoint point = other.GetContact(0);
         _vel -= point.normal * Mathf.Min(Vector3.Dot(_vel, point.normal), 0);
         if (landingBounce)
         {
             kickController.AddVel(Vector3.up * (_vel.y * landingBounceScale));
         }
     }
 }
Exemple #2
0
    void Fire()
    {
        if (_bullets == 0)
        {
            // play clicking noise?
            return;
        }
        _weapon.SetFloat(HitscanGun.BulletsIndex, _bullets - 1);

        if (!silenced)
        {
            _chadistAI.SpotPlayer(transform.position);
        }

        Ray shotRay = new Ray(_weapon.cam.transform.position, _weapon.cam.transform.rotation * Vector3.forward);

        if (Physics.Raycast(shotRay, out RaycastHit hit, Mathf.Infinity, layerMask))
        {
            // we hit something???
            Transform hitObject = hit.transform;
            Rigidbody hitRB     = hitObject.GetComponent <Rigidbody>();
            if (hitRB)
            {
                hitRB.AddForceAtPosition(shotRay.direction * kineticPower, hit.point);
            }

            Damageable damageable = hitObject.GetComponent <Damageable>();
            if (damageable)
            {
                damageable.Shoot(new PlayerShotInfo(_weapon.playerInventory, _weapon, damage, hit, shotRay.direction));
                if (damageable.fxPrefab)
                {
                    SpawnHitFX(damageable.fxPrefab, hit);
                }
                else
                {
                    SpawnHitFX(defaultHitPrefab, hit);
                }
            }
            else
            {
                // spawn fx
                SpawnHitFX(defaultHitPrefab, hit);
            }
        }

        _kickController.AddVel(_weapon.cam.transform.TransformVector(Vector3.forward * (-kickBack)));
        _kickController.AddKick(Quaternion.Euler(-kickRotation, 0, 0));

        _lastShot = Time.time;
        animator.SetTrigger("fire");
    }