feat : basic footstep controller system

This commit is contained in:
Hugo Le Bolloc'h
2026-03-27 16:28:39 +01:00
parent 933445214b
commit 7b4ea05716
19 changed files with 505 additions and 40180 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,87 @@
using UnityEngine;
using System.Collections.Generic;
using AK.Wwise;
[RequireComponent(typeof(CharacterController))]
public class Audio_FootstepsController : MonoBehaviour
{
[System.Serializable]
public struct SurfaceMapping
{
public string tag;
public AK.Wwise.Switch wwiseSwitch;
}
[Header("Wwise Assets")]
public AK.Wwise.Event footstepEvent;
[Header("Surface Configuration")]
public List<SurfaceMapping> surfaces = new List<SurfaceMapping>();
public AK.Wwise.Switch defaultSwitch;
[Header("Movement Settings")]
[SerializeField] private float stepInterval = 0.5f;
[SerializeField] private float minVelocity = 0.1f;
[SerializeField] private float rayDistance = 1.2f;
[SerializeField] private LayerMask groundLayer;
private CharacterController _controller;
private float _timer;
private Dictionary<string, AK.Wwise.Switch> _surfaceCache;
void Awake()
{
_controller = GetComponent<CharacterController>();
// On remplit le dictionnaire pour un accès ultra-rapide par le nom du tag
_surfaceCache = new Dictionary<string, AK.Wwise.Switch>();
foreach (var mapping in surfaces)
{
if (!string.IsNullOrEmpty(mapping.tag))
{
// On stocke en minuscule pour éviter les erreurs de casse
_surfaceCache[mapping.tag.ToLower()] = mapping.wwiseSwitch;
}
}
}
void Update()
{
if (_controller.isGrounded && _controller.velocity.magnitude > minVelocity)
{
_timer += Time.deltaTime;
if (_timer >= stepInterval)
{
PlayFootstep();
_timer = 0f;
}
}
else
{
_timer = stepInterval;
}
}
private void PlayFootstep()
{
RaycastHit hit;
if (Physics.Raycast(transform.position + Vector3.up * 0.1f, Vector3.down, out hit, rayDistance, groundLayer))
{
string currentTag = hit.collider.tag.ToLower();
// On cherche le switch dans le dictionnaire
if (_surfaceCache.TryGetValue(currentTag, out AK.Wwise.Switch targetSwitch))
{
targetSwitch.SetValue(gameObject);
// Debug.Log($"[Footsteps] Switch Wwise réglé sur : {currentTag}");
}
else
{
defaultSwitch.SetValue(gameObject);
Debug.LogWarning($"[Footsteps] Tag '{currentTag}' inconnu. Utilisation du switch par défaut.");
}
footstepEvent.Post(gameObject);
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5a11b07babb12d446a356745e7a37303