Platformer example started

This commit is contained in:
ThomasCharester committed 2026-02-22 13:59:04 +03:00
1 parent efcfaae647
commit 9f026b76d6
325 files changed
+23540 -270

No files matched your search

@@ -8,5 +8,29 @@ namespace Code.Example.Race.Racer.AI
{
SteeringInput = steeringLinear;
}
protected override void Brake()
{
if (CarRb.linearVelocity.magnitude > 10f && (SteeringInput.y > CarRb.linearVelocity.y || SteeringInput.x > CarRb.linearVelocity.x))
{
foreach (var wheel in wheels)
{
wheel.wheelCollider.brakeTorque = 100 * 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();
}
}
}
}
@@ -11,6 +11,7 @@ namespace Code.Example.Race.Racer.AI
{
[Inject] private EventBus _eventBus;
[SerializeField] private CarControllerRB carController;
public override void SetData(RacerData data)
{
Data = data;
@@ -10,7 +10,7 @@ namespace Code.Example.Race.Racer.AI.ID.Behaviours
steering.linear = transform.position - target.position;
steering.linear.Normalize();
steering.linear *= agent.Data.maxAcceleration;
// steering.linear *= agent.Data.maxAcceleration;
return steering;
}
}
@@ -0,0 +1,42 @@
using UnityEngine;
using System.Collections;
namespace Code.Example.Race.Racer.AI.ID.Behaviours
{
public class Pursue : Seek
{
public float maxPrediction;
private GameObject _targetAux;
private GameObject _target;
public void Awake()
{
_targetAux = _target;
_target = new GameObject();
}
void OnDestroy()
{
Destroy(_targetAux);
}
public override Steering GetSteering(Transform targetTransform)
{
var direction = _targetAux.transform.position - transform.position;
var distance = direction.magnitude;
var speed = agent.CarRigidbody.linearVelocity.magnitude;
float prediction;
if (speed <= distance / maxPrediction)
prediction = maxPrediction;
else
prediction = distance / speed;
_target.transform.position = _targetAux.transform.position;
// _target.transform.position += targetAgent.velocity * prediction;
return base.GetSteering(_target.transform);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c3a071d2cab443528dd16bdc044bab65
timeCreated: 1770998212
@@ -11,8 +11,7 @@ namespace Code.Example.Race.Racer.AI.ID.Behaviours
steering.linear = target.position - transform.position;
UnityEngine.Debug.DrawRay(transform.position, steering.linear, Color.yellow, 5f);
// steering.linear *= agent.Data.maxAcceleration;
steering.linear.Normalize();
UnityEngine.Debug.Log(steering.linear);
steering.linear.Normalize();
return steering;
}
}
@@ -34,7 +34,7 @@ namespace Code.Example.Race.Racer
public List<Wheel> wheels;
protected Rigidbody CarRb;
protected Rigidbody CarRb;
protected Vector2 SteeringInput = Vector2.zero;
public abstract void SetSteering(Vector2 steeringLinear);
@@ -16,9 +16,9 @@ namespace Code.Example.Race.Racer.Player
{
_inputService = inputService;
_inputService.BindActionPerformed((int)ActionMappings.Gameplay, (int)GameplayActions.Move, MovementPerformed);
_inputService.BindActionCancel((int)ActionMappings.Gameplay, (int)GameplayActions.Move, MovementEnded);
_inputService.BindActionCancelled((int)ActionMappings.Gameplay, (int)GameplayActions.Move, MovementEnded);
_inputService.BindActionPerformed((int)ActionMappings.Gameplay, (int)GameplayActions.Brake, BrakePerformed);
_inputService.BindActionCancel((int)ActionMappings.Gameplay, (int)GameplayActions.Brake, BrakeEnded);
_inputService.BindActionCancelled((int)ActionMappings.Gameplay, (int)GameplayActions.Brake, BrakeEnded);
}
private void MovementPerformed(InputAction.CallbackContext context) => MovementInput = context.ReadValue<Vector2>();
@@ -33,9 +33,9 @@ namespace Code.Example.Race.Racer.Player
{
if (_inputService == null) return;
_inputService.UnbindActionPerformed((int)ActionMappings.Gameplay, (int)GameplayActions.Move, MovementPerformed);
_inputService.UnbindActionCanceled((int)ActionMappings.Gameplay, (int)GameplayActions.Move, MovementEnded);
_inputService.UnbindActionCancelled((int)ActionMappings.Gameplay, (int)GameplayActions.Move, MovementEnded);
_inputService.UnbindActionPerformed((int)ActionMappings.Gameplay, (int)GameplayActions.Brake, BrakePerformed);
_inputService.UnbindActionCanceled((int)ActionMappings.Gameplay, (int)GameplayActions.Brake, BrakeEnded);
_inputService.UnbindActionCancelled((int)ActionMappings.Gameplay, (int)GameplayActions.Brake, BrakeEnded);
}
}
}