...
This commit is contained in:
32
Assets/Scripts/Character/AutoAim.cs
Normal file
32
Assets/Scripts/Character/AutoAim.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class AutoAim : MonoBehaviour
|
||||
{
|
||||
|
||||
public GameObject enemy;
|
||||
|
||||
public float lookSpeed = 200;
|
||||
|
||||
public GameObject head;
|
||||
public Camera cam;
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (enemy)
|
||||
{
|
||||
Vector3 direction = enemy.transform.position - cam.transform.position;
|
||||
Quaternion targetRotation = Quaternion.LookRotation(direction);
|
||||
Quaternion lookAt = Quaternion.RotateTowards(cam.transform.rotation, targetRotation, Time.deltaTime * lookSpeed);
|
||||
cam.transform.rotation = lookAt;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Character/AutoAim.cs.meta
generated
Normal file
11
Assets/Scripts/Character/AutoAim.cs.meta
generated
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e60a742d011f2dc4ca582f689dc94f1b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -4,6 +4,7 @@ using Unity.MLAgents;
|
||||
using Unity.MLAgents.Sensors;
|
||||
using Unity.MLAgents.Actuators;
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
[RequireComponent(typeof(MovementController))]
|
||||
public class NPC : Agent, ICharacter
|
||||
@ -21,6 +22,9 @@ public class NPC : Agent, ICharacter
|
||||
private MovementController moveController;
|
||||
private BufferSensorComponent bufferSensor;
|
||||
|
||||
[SerializeField] [NotNull]
|
||||
private NavPoint DumbAIDestination;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
DirectState = new NPC_DirectPointState();
|
||||
@ -31,6 +35,7 @@ public class NPC : Agent, ICharacter
|
||||
AgentCharacter = new Character();
|
||||
Condition = AgentCharacter.Condition;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
AgentCharacter = new Character();
|
||||
@ -44,7 +49,7 @@ public class NPC : Agent, ICharacter
|
||||
|
||||
public override void OnEpisodeBegin()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void CollectObservations(VectorSensor sensor)
|
||||
@ -52,7 +57,7 @@ public class NPC : Agent, ICharacter
|
||||
sensor.AddObservation(Condition.HealthPoints);
|
||||
sensor.AddObservation(Condition.ArmourPoints);
|
||||
sensor.AddObservation(Condition.Ammunition);
|
||||
sensor.AddObservation((int)NPC_State.State);
|
||||
sensor.AddObservation((int) NPC_State.State);
|
||||
|
||||
|
||||
|
||||
@ -60,32 +65,36 @@ public class NPC : Agent, ICharacter
|
||||
foreach (var point in candidates)
|
||||
{
|
||||
|
||||
bufferSensor.AppendObservation(new float[] {
|
||||
bufferSensor.AppendObservation(new float[]
|
||||
{
|
||||
//1 position in navpointId
|
||||
(float)moveController.currentPosition.PointId,
|
||||
(float) moveController.currentPosition.PointId,
|
||||
//2 distance to flag
|
||||
moveController.currentPosition.FlagDistance,
|
||||
//3 death count in point
|
||||
moveController.currentPosition.DeathAttr,
|
||||
//4 flagEnemyDistance
|
||||
GameManager.IsCloserToFlagFromNextNavPoint(point, transform.position)==true?1:0,
|
||||
GameManager.IsCloserToFlagFromNextNavPoint(point, transform.position) == true ? 1 : 0,
|
||||
//5 EnemyVsNavPointDistance
|
||||
GameManager.IsCloserToEnemyThanToNextNavPoint(point,transform.position, AgentCharacter.Team)==true?1:0
|
||||
});
|
||||
GameManager.IsCloserToEnemyThanToNextNavPoint(point, transform.position, AgentCharacter.Team) == true
|
||||
? 1
|
||||
: 0
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public override void Heuristic(in ActionBuffers actionsOut)
|
||||
{
|
||||
var discreteActionsOut = actionsOut.DiscreteActions;
|
||||
if (Input.GetKeyDown(KeyCode.W))
|
||||
{
|
||||
discreteActionsOut[0] = 1;
|
||||
}
|
||||
moveController.goToNextNavPoint(DumbAIDestination);
|
||||
}
|
||||
|
||||
public override void OnActionReceived(ActionBuffers actions)
|
||||
public void DumbAIAction()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void OnActionReceived(ActionBuffers actions)
|
||||
{
|
||||
if (actions.DiscreteActions[0] == 1)
|
||||
{
|
||||
|
@ -72,10 +72,6 @@ public class scr_CharacterController : MonoBehaviour
|
||||
|
||||
public AudioClip aftergunSound;
|
||||
public AudioSource gunSound;
|
||||
|
||||
public int count_of_bullets = 120;
|
||||
public int count_of_bullets_gun = 30;
|
||||
private int current_count_of_bullets_gun = 30;
|
||||
private void Awake()
|
||||
{
|
||||
defaultInput = new DefaultInput();
|
||||
@ -106,39 +102,18 @@ public class scr_CharacterController : MonoBehaviour
|
||||
}
|
||||
|
||||
void PlayShootingSound()
|
||||
{
|
||||
{
|
||||
gunSound.volume = 1;
|
||||
gunSound.PlayOneShot(gunSound.clip);
|
||||
gunSound.PlayOneShot(aftergunSound);
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown("r"))
|
||||
{
|
||||
Debug.Log("Reload");
|
||||
int difference = 0;
|
||||
if (count_of_bullets_gun == current_count_of_bullets_gun)
|
||||
return;
|
||||
if (current_count_of_bullets_gun < count_of_bullets_gun)
|
||||
{
|
||||
difference = count_of_bullets_gun - current_count_of_bullets_gun;
|
||||
if (count_of_bullets > difference)
|
||||
{
|
||||
current_count_of_bullets_gun = count_of_bullets_gun;
|
||||
count_of_bullets -= count_of_bullets_gun;
|
||||
}
|
||||
else
|
||||
{
|
||||
current_count_of_bullets_gun = count_of_bullets;
|
||||
count_of_bullets = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Input.GetButtonDown("Fire1") && current_count_of_bullets_gun > 0)
|
||||
|
||||
if (Input.GetButtonDown("Fire1"))
|
||||
{
|
||||
PlayShootingSound();
|
||||
Shoot();
|
||||
Debug.Log(current_count_of_bullets_gun);
|
||||
current_count_of_bullets_gun -= 5;
|
||||
}
|
||||
CalculateView();
|
||||
CalculateMovement();
|
||||
@ -153,7 +128,10 @@ public class scr_CharacterController : MonoBehaviour
|
||||
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
|
||||
{
|
||||
Debug.Log(hit.transform.name);
|
||||
|
||||
|
||||
//Vector3 forward = transform.TransformDirection(Vector3.forward) * 30;
|
||||
//Debug.DrawRay(transform.position, forward, Color.green);
|
||||
|
||||
Target target = hit.transform.GetComponent<Target>();
|
||||
if (target != null)
|
||||
{
|
||||
|
@ -18,6 +18,7 @@ public class Target : MonoBehaviour
|
||||
void Die()
|
||||
{
|
||||
Destroy(gameObject);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user