ИИ гонщиков, запуск, перезапуск игры и пр
This commit is contained in:
1 parent
f557c58c9d
commit
efcfaae647
48 files changed
+1486
-212
No files matched your search
@@ -1,11 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using Code.Example.Race.Racer.AI.ID;
|
||||
using Code.Example.Race.Track;
|
||||
using Code.Infrastructure.EventBus;
|
||||
using Reflex.Attributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Example.Race.Racer.AI
|
||||
{
|
||||
public class AIRacerID : Racer
|
||||
{
|
||||
[Inject] private EventBus _eventBus;
|
||||
[SerializeField] private CarControllerRB carController;
|
||||
public override void SetData(RacerData data)
|
||||
{
|
||||
Data = data;
|
||||
@@ -21,9 +26,10 @@ namespace Code.Example.Race.Racer.AI
|
||||
|
||||
public override void NextWaypoint()
|
||||
{
|
||||
if(CurrentWaypointIndex >= Waypoints.Count) CurrentWaypointIndex = 0;
|
||||
if (++CurrentWaypointIndex < Waypoints.Count) return;
|
||||
|
||||
CurrentWaypointIndex++;
|
||||
CurrentWaypointIndex = 0;
|
||||
_eventBus.RaiseEvent<IRacerPassedCheckpointHandler>(x=> x.LapPassed(this));
|
||||
}
|
||||
|
||||
public override void StartRacer()
|
||||
@@ -66,33 +72,38 @@ namespace Code.Example.Race.Racer.AI
|
||||
{
|
||||
if (!_running) return;
|
||||
|
||||
var displacement = _velocity * Time.deltaTime;
|
||||
_orientation += _rotation * Time.deltaTime;
|
||||
_orientation = NormalizeAngle(_orientation);
|
||||
var steering =
|
||||
transform.InverseTransformDirection(
|
||||
agent.GetSteering(Waypoints[CurrentWaypointIndex]).linear);
|
||||
|
||||
transform.Translate(displacement, Space.World);
|
||||
transform.Rotate(Vector3.up, _orientation);
|
||||
carController.SetSteering(new Vector2(steering.x, steering.z));
|
||||
// var displacement = _velocity * Time.deltaTime;
|
||||
// _orientation += _rotation * Time.deltaTime;
|
||||
// _orientation = NormalizeAngle(_orientation);
|
||||
//
|
||||
// transform.Translate(displacement, Space.World);
|
||||
// transform.Rotate(Vector3.up, _orientation);
|
||||
}
|
||||
public virtual void LateUpdate()
|
||||
{
|
||||
if (!_running) return;
|
||||
|
||||
_steering = agent.GetSteering(Waypoints[CurrentWaypointIndex]);
|
||||
|
||||
_velocity += _steering.linear * Time.deltaTime;
|
||||
_rotation += _steering.angular * Time.deltaTime;
|
||||
if (_velocity.magnitude > Data.speed)
|
||||
{
|
||||
_velocity = _velocity.normalized * Data.speed;
|
||||
}
|
||||
if (_steering.angular == 0.0f)
|
||||
{
|
||||
_rotation = 0.0f;
|
||||
}
|
||||
if (_steering.linear.sqrMagnitude == 0.0f)
|
||||
{
|
||||
_velocity = Vector3.zero;
|
||||
}
|
||||
//
|
||||
// _steering = agent.GetSteering(Waypoints[CurrentWaypointIndex]);
|
||||
//
|
||||
// _velocity += _steering.linear * Time.deltaTime;
|
||||
// _rotation += _steering.angular * Time.deltaTime;
|
||||
// if (_velocity.magnitude > Data.speed)
|
||||
// {
|
||||
// _velocity = _velocity.normalized * Data.speed;
|
||||
// }
|
||||
// if (_steering.angular == 0.0f)
|
||||
// {
|
||||
// _rotation = 0.0f;
|
||||
// }
|
||||
// if (_steering.linear.sqrMagnitude == 0.0f)
|
||||
// {
|
||||
// _velocity = Vector3.zero;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user