ИИ гонщиков, запуск, перезапуск игры и пр
This commit is contained in:
1 parent
f557c58c9d
commit
efcfaae647
48 files changed
+1486
-212
No files matched your search
@@ -1,162 +0,0 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Code.Example.Race.Racer.AI;
|
||||
|
||||
namespace Code.Example.Race.Racer.Player
|
||||
{
|
||||
public class PlayerCarControllerRB : MonoBehaviour
|
||||
{
|
||||
public enum ControlMode
|
||||
{
|
||||
Keyboard,
|
||||
Buttons
|
||||
};
|
||||
|
||||
public enum Axel
|
||||
{
|
||||
Front,
|
||||
Rear
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct Wheel
|
||||
{
|
||||
public GameObject wheelModel;
|
||||
public WheelCollider wheelCollider;
|
||||
public GameObject wheelEffectObj;
|
||||
public ParticleSystem smokeParticle;
|
||||
public Axel axel;
|
||||
}
|
||||
|
||||
public ControlMode control;
|
||||
|
||||
public Vector3 _centerOfMass;
|
||||
|
||||
public List<Wheel> wheels;
|
||||
|
||||
private Rigidbody carRb;
|
||||
|
||||
[SerializeField] private PlayerCarInput _playerCarInput;
|
||||
[SerializeField] private PlayerRacer _playerRacer;
|
||||
|
||||
|
||||
// private CarLights carLights;
|
||||
|
||||
void Start()
|
||||
{
|
||||
carRb = GetComponent<Rigidbody>();
|
||||
carRb.centerOfMass = _centerOfMass;
|
||||
|
||||
// carLights = GetComponent<CarLights>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// GetInputs();
|
||||
AnimateWheels();
|
||||
// WheelEffects();
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
Move();
|
||||
Steer();
|
||||
Brake();
|
||||
}
|
||||
|
||||
// public void MoveInput(float input)
|
||||
// {
|
||||
// moveInput = input;
|
||||
// }
|
||||
//
|
||||
// public void SteerInput(float input)
|
||||
// {
|
||||
// steerInput = input;
|
||||
// }
|
||||
|
||||
void GetInputs()
|
||||
{
|
||||
// if (control == ControlMode.Keyboard)
|
||||
// {
|
||||
// moveInput = Input.GetAxis("Vertical");
|
||||
// steerInput = Input.GetAxis("Horizontal");
|
||||
// }
|
||||
}
|
||||
|
||||
void Move()
|
||||
{
|
||||
foreach (var wheel in wheels)
|
||||
{
|
||||
wheel.wheelCollider.motorTorque = _playerCarInput.MovementInput.y * 600 * _playerRacer.Data.maxAcceleration * Time.fixedDeltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
void Steer()
|
||||
{
|
||||
foreach (var wheel in wheels)
|
||||
{
|
||||
if (wheel.axel != Axel.Front) continue;
|
||||
|
||||
var _steerAngle = _playerCarInput.MovementInput.x * _playerRacer.Data.turnSensitivity * _playerRacer.Data.maxSteerAngle;
|
||||
wheel.wheelCollider.steerAngle = _steerAngle;
|
||||
// wheel.wheelCollider.steerAngle = Mathf.Lerp(wheel.wheelCollider.steerAngle, _steerAngle, 0.6f);
|
||||
}
|
||||
}
|
||||
|
||||
void Brake()
|
||||
{
|
||||
if (_playerCarInput.Brake || _playerCarInput.MovementInput.y == 0)
|
||||
{
|
||||
foreach (var wheel in wheels)
|
||||
{
|
||||
wheel.wheelCollider.brakeTorque = 300 * _playerRacer.Data.brakeAcceleration * Time.fixedDeltaTime;
|
||||
}
|
||||
|
||||
// carLights.isBackLightOn = true;
|
||||
// carLights.OperateBackLights();
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var wheel in wheels)
|
||||
{
|
||||
wheel.wheelCollider.brakeTorque = 0;
|
||||
}
|
||||
|
||||
// carLights.isBackLightOn = false;
|
||||
// carLights.OperateBackLights();
|
||||
}
|
||||
}
|
||||
|
||||
void AnimateWheels()
|
||||
{
|
||||
foreach (var wheel in wheels)
|
||||
{
|
||||
Quaternion rot;
|
||||
Vector3 pos;
|
||||
wheel.wheelCollider.GetWorldPose(out pos, out rot);
|
||||
wheel.wheelModel.transform.position = pos;
|
||||
wheel.wheelModel.transform.rotation = rot;
|
||||
}
|
||||
}
|
||||
|
||||
void WheelEffects()
|
||||
{
|
||||
foreach (var wheel in wheels)
|
||||
{
|
||||
//var dirtParticleMainSettings = wheel.smokeParticle.main;
|
||||
|
||||
if (wheel.axel == Axel.Rear && wheel.wheelCollider.isGrounded &&
|
||||
carRb.linearVelocity.magnitude >= 10.0f)
|
||||
{
|
||||
// wheel.wheelEffectObj.GetComponentInChildren<TrailRenderer>().emitting = true;
|
||||
// wheel.smokeParticle.Emit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// wheel.wheelEffectObj.GetComponentInChildren<TrailRenderer>().emitting = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f093c913ff54cb99cd22d7e473931e7
|
||||
timeCreated: 1770299509
|
||||
@@ -0,0 +1,44 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Example.Race.Racer.Player
|
||||
{
|
||||
public class PlayerRBCarController : CarControllerRB
|
||||
{
|
||||
[SerializeField] private PlayerCarInput playerCarInput;
|
||||
|
||||
public override void SetSteering(Vector2 steeringLinear)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
SteeringInput = playerCarInput.MovementInput;
|
||||
base.Update();
|
||||
}
|
||||
|
||||
protected override void Brake()
|
||||
{
|
||||
if (playerCarInput.Brake )
|
||||
{
|
||||
foreach (var wheel in wheels)
|
||||
{
|
||||
wheel.wheelCollider.brakeTorque = 300 * racer.Data.brakeAcceleration * Time.fixedDeltaTime;
|
||||
}
|
||||
|
||||
// carLights.isBackLightOn = true;
|
||||
// carLights.OperateBackLights();
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var wheel in wheels)
|
||||
{
|
||||
wheel.wheelCollider.brakeTorque = 0;
|
||||
}
|
||||
|
||||
// carLights.isBackLightOn = false;
|
||||
// carLights.OperateBackLights();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bad2326aa0f24acb9bdfeb5fb7d3d208
|
||||
timeCreated: 1770640123
|
||||
@@ -1,10 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using Code.Example.Race.Track;
|
||||
using Code.Infrastructure.EventBus;
|
||||
using Reflex.Attributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Example.Race.Racer.Player
|
||||
{
|
||||
public class PlayerRacer : Racer
|
||||
{
|
||||
[Inject] private EventBus _eventBus;
|
||||
|
||||
public Transform CameraPosition;
|
||||
public override void SetData(RacerData data)
|
||||
{
|
||||
@@ -13,21 +18,26 @@ namespace Code.Example.Race.Racer.Player
|
||||
|
||||
public override void Initialize(List<Transform> waypoints)
|
||||
{
|
||||
|
||||
Waypoints = waypoints;
|
||||
}
|
||||
|
||||
public override void NextWaypoint()
|
||||
{
|
||||
if (++CurrentWaypointIndex < Waypoints.Count) return;
|
||||
|
||||
CurrentWaypointIndex = 0;
|
||||
_eventBus.RaiseEvent<IPlayerPassedCheckpointHandler>(x=> x.OnPlayerLapPassed(this));
|
||||
_eventBus.RaiseEvent<IRacerPassedCheckpointHandler>(x=> x.LapPassed(this));
|
||||
}
|
||||
|
||||
public bool RaceStarted { get; set; }
|
||||
public override void StartRacer()
|
||||
{
|
||||
|
||||
RaceStarted = true;
|
||||
}
|
||||
|
||||
public override void StopRacer()
|
||||
{
|
||||
RaceStarted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user