fixed player in bot fights and their scaled time features (player not time scaled). Now player can join to fights for justice.
This commit is contained in:
@ -1,11 +1,12 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using Weapons;
|
||||
|
||||
[RequireComponent(typeof(NPC))]
|
||||
public class AimAssistant : MonoBehaviour
|
||||
{
|
||||
[HideInInspector] public GameObject enemy;
|
||||
private Shooting _shooting;
|
||||
private BotShooter _botShooter;
|
||||
public bool isFiring = false;
|
||||
private NPC _myNpc;
|
||||
[SerializeField] private float lookSpeed = 400f;
|
||||
@ -19,14 +20,13 @@ public class AimAssistant : MonoBehaviour
|
||||
private void Awake()
|
||||
{
|
||||
_myNpc = GetComponent<NPC>();
|
||||
_shooting = GetComponent<Shooting>();
|
||||
_botShooter = GetComponent<BotShooter>();
|
||||
_myTransform = transform;
|
||||
_fireCountdown = 1f / SettingsReader.Instance.GetSettings.RateOfFire;
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
//Ищем противника на сцене.
|
||||
if (isFiring == false)
|
||||
{
|
||||
var enemies = GameManager.GetVisibleEnemies(_myNpc.GetCharacter.Team.GetOppositeTeam(), transform.position);
|
||||
@ -72,6 +72,7 @@ public class AimAssistant : MonoBehaviour
|
||||
if (enemy != null)
|
||||
{
|
||||
var direction = enemy.transform.position - gameObject.transform.position;
|
||||
if (direction == Vector3.zero) return;
|
||||
var targetRotation = Quaternion.LookRotation(direction);
|
||||
var lookAt = Quaternion.RotateTowards(gameObject.transform.rotation, targetRotation,
|
||||
Time.deltaTime * lookSpeed);
|
||||
@ -92,8 +93,9 @@ public class AimAssistant : MonoBehaviour
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
_shooting.BotShoot();
|
||||
_botShooter.BotShoot();
|
||||
yield return new WaitForSeconds(_fireCountdown);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
50
Assets/Scripts/Weapons/BotShooter.cs
Normal file
50
Assets/Scripts/Weapons/BotShooter.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Weapons
|
||||
{
|
||||
public class BotShooter : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject firePoint;
|
||||
[SerializeField] private ParticleSystem projectilePrefab;
|
||||
private NPC _myNpc;
|
||||
private MovementController _moveCtrl;
|
||||
private AudioSource _audioSource;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_myNpc = GetComponent<NPC>();
|
||||
_moveCtrl = GetComponent<MovementController>();
|
||||
_audioSource = GetComponent<AudioSource>();
|
||||
}
|
||||
|
||||
public void BotShoot()
|
||||
{
|
||||
if (Physics.Raycast(firePoint.transform.position,
|
||||
firePoint.transform.forward, out var hit,
|
||||
SettingsReader.Instance.GetSettings.ViewDistance))
|
||||
{
|
||||
if (hit.transform.TryGetComponent<ICharacter>(out var target))
|
||||
{
|
||||
print($"did damage to {hit.transform.name}");
|
||||
_audioSource.Play();
|
||||
Instantiate(projectilePrefab, firePoint.transform.position, firePoint.transform.rotation);
|
||||
var mySpeed = _moveCtrl.Velocity.magnitude;
|
||||
var enemySpeed = 0f;
|
||||
var inCover = false;
|
||||
if (target.GetCharacter.TypeAi == TypeAI.HumanAI)
|
||||
enemySpeed = hit.rigidbody.velocity.magnitude;
|
||||
else
|
||||
{
|
||||
enemySpeed = hit.collider.GetComponent<MovementController>().Velocity.magnitude;
|
||||
inCover = hit.collider.GetComponent<NPC>().NpcState.InCover;
|
||||
}
|
||||
|
||||
var hitChance = (1 - 0.5 * mySpeed) * (1 - 0.5 * enemySpeed + 0.5*inCover.ToInt()) / 1.5f;
|
||||
if (!(Random.Range(0f, 1f) < hitChance)) return;
|
||||
_myNpc.AddReward(0.05f);
|
||||
target.GetDamage(SettingsReader.Instance.GetSettings.RifleDamage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Weapons/BotShooter.cs.meta
generated
Normal file
3
Assets/Scripts/Weapons/BotShooter.cs.meta
generated
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2a6ce8ea5e584f40922a36bdb4219494
|
||||
timeCreated: 1652982070
|
57
Assets/Scripts/Weapons/PlayerShooter.cs
Normal file
57
Assets/Scripts/Weapons/PlayerShooter.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using Animators.Leonid_Animator.Player;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Weapons
|
||||
{
|
||||
[RequireComponent(typeof(AudioSource))]
|
||||
[RequireComponent(typeof(InputHandler))]
|
||||
public class PlayerShooter : MonoBehaviour
|
||||
{
|
||||
public GameObject firePoint;
|
||||
|
||||
public ParticleSystem projectilePrefab;
|
||||
|
||||
private float _fireCountdown = 0.5f;
|
||||
|
||||
private AudioSource _audioSource;
|
||||
private InputHandler _inputHandler;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_audioSource = GetComponent<AudioSource>();
|
||||
_inputHandler = GetComponent<InputHandler>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
HandleMouseButton();
|
||||
}
|
||||
|
||||
private void HandleMouseButton()
|
||||
{
|
||||
if (_inputHandler.firePressed && _fireCountdown <= 0f)
|
||||
{
|
||||
_fireCountdown = 0.5f;
|
||||
PlayerShoot();
|
||||
}
|
||||
|
||||
_fireCountdown -= Time.unscaledDeltaTime;
|
||||
}
|
||||
|
||||
private void PlayerShoot()
|
||||
{
|
||||
_audioSource.Play();
|
||||
Instantiate(projectilePrefab, firePoint.transform.position, firePoint.transform.rotation);
|
||||
if (Physics.Raycast(firePoint.transform.position,
|
||||
firePoint.transform.forward, out var hit,
|
||||
SettingsReader.Instance.GetSettings.ViewDistance))
|
||||
{
|
||||
if (hit.transform.TryGetComponent<NPC>(out var target))
|
||||
{
|
||||
print($"did damage to {hit.transform.name}");
|
||||
target.GetDamage(SettingsReader.Instance.GetSettings.RifleDamage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(AudioSource))]
|
||||
public class Shooting : MonoBehaviour
|
||||
{
|
||||
public GameObject raycast;
|
||||
|
||||
public GameObject firePoint;
|
||||
|
||||
public ParticleSystem projectilePrefab;
|
||||
|
||||
private float hSliderValue = 0.1f;
|
||||
private float _fireCountdown = 0.1f;
|
||||
|
||||
public AudioSource audioSource;
|
||||
private NPC _myNpc;
|
||||
private MovementController _moveCtrl;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
TryGetComponent(out _moveCtrl);
|
||||
TryGetComponent(out _myNpc);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
HandleMouseButton();
|
||||
}
|
||||
|
||||
private void HandleMouseButton()
|
||||
{
|
||||
if (Input.GetMouseButton(0) && _fireCountdown <= 0f)
|
||||
{
|
||||
_fireCountdown = 0;
|
||||
_fireCountdown += hSliderValue;
|
||||
PlayerShoot();
|
||||
}
|
||||
|
||||
_fireCountdown -= Time.deltaTime;
|
||||
}
|
||||
|
||||
private void PlayerShoot()
|
||||
{
|
||||
audioSource.Play();
|
||||
Instantiate(projectilePrefab, firePoint.transform.position, firePoint.transform.rotation);
|
||||
if (Physics.Raycast(raycast.transform.position,
|
||||
raycast.transform.forward, out var hit,
|
||||
SettingsReader.Instance.GetSettings.ViewDistance))
|
||||
{
|
||||
if (hit.transform.TryGetComponent<NPC>(out var target))
|
||||
{
|
||||
target.GetDamage(SettingsReader.Instance.GetSettings.RifleDamage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void BotShoot()
|
||||
{
|
||||
if (Physics.Raycast(raycast.transform.position,
|
||||
raycast.transform.forward, out var hit,
|
||||
SettingsReader.Instance.GetSettings.ViewDistance))
|
||||
{
|
||||
if (hit.transform.TryGetComponent<ICharacter>(out var target))
|
||||
{
|
||||
audioSource.Play();
|
||||
Instantiate(projectilePrefab, firePoint.transform.position, firePoint.transform.rotation);
|
||||
var mySpeed = _moveCtrl.Velocity.magnitude;
|
||||
var enemySpeed = 0f;
|
||||
var inCover = false;
|
||||
if (target.GetCharacter.TypeAi == TypeAI.HumanAI)
|
||||
enemySpeed = hit.rigidbody.velocity.magnitude;
|
||||
else
|
||||
{
|
||||
enemySpeed = hit.collider.GetComponent<MovementController>().Velocity.magnitude;
|
||||
inCover = hit.collider.GetComponent<NPC>().NpcState.InCover;
|
||||
}
|
||||
|
||||
var hitChance = (1 - 0.5 * mySpeed) * (1 - 0.5 * enemySpeed + 0.5*inCover.ToInt()) / 1.5f;
|
||||
if (!(UnityEngine.Random.Range(0f, 1f) < hitChance)) return;
|
||||
_myNpc.AddReward(0.05f);
|
||||
target.GetDamage(SettingsReader.Instance.GetSettings.RifleDamage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user