Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

50 changes: 50 additions & 0 deletions Unity_jeu/Assets/Liam_Composant/Scene 2/CameraShake.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using UnityEngine;

public class CameraShake : MonoBehaviour
{
[Header("R�glages")]
public float amplitude = 0.05f;
public float frequency = 25f;
public float smooth = 5f;

private Vector3 initialPos;
private bool shaking = false;
private float shakeTime = 0f;
private float baseAmplitude;

void Start()
{
initialPos = transform.localPosition;
baseAmplitude = amplitude;
}

void Update()
{
if (shaking)
{
shakeTime += Time.deltaTime * frequency;
float offsetX = Mathf.PerlinNoise(shakeTime, 0f) * 2f - 1f;
float offsetY = Mathf.PerlinNoise(0f, shakeTime) * 2f - 1f;

Vector3 shakeOffset = new Vector3(offsetX, offsetY, 0f) * amplitude;
transform.localPosition = initialPos + shakeOffset;
}
else
{
transform.localPosition = Vector3.Lerp(transform.localPosition, initialPos, Time.deltaTime * smooth);
}
}

public void SetShaking(bool active)
{
shaking = active;
if (!active) shakeTime = 0f;
}

public void SetShaking(bool active, float intensity)
{
shaking = active;
amplitude = baseAmplitude * Mathf.Clamp01(intensity);
if (!active) shakeTime = 0f;
}
}
2 changes: 2 additions & 0 deletions Unity_jeu/Assets/Liam_Composant/Scene 2/CameraShake.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Unity_jeu/Assets/Liam_Composant/Scene 2/Pathfinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System;
using Debug = UnityEngine.Debug;

public class Pathfinding : MonoBehaviour
{
Expand All @@ -18,6 +19,8 @@ void Awake()

public void FindPath(PathRequest request, Action<PathResult> callback)
{
Debug.Log($"[Pathfinding] FindPath called from {request.pathStart} to {request.pathEnd}");

Stopwatch sw = new Stopwatch();
sw.Start();

Expand All @@ -27,6 +30,14 @@ public void FindPath(PathRequest request, Action<PathResult> callback)
Node startNode = grid.NodeFromWorldPoint(request.pathStart);
Node targetNode = grid.NodeFromWorldPoint(request.pathEnd);

Debug.Log($"[PF] Start node: ({startNode.gridX},{startNode.gridY}) walkable={startNode.walkable}");
Debug.Log($"[PF] Target node: ({targetNode.gridX},{targetNode.gridY}) walkable={targetNode.walkable}");

if (!startNode.walkable || !targetNode.walkable)
{
Debug.LogWarning("[PF] Start or Target node NOT walkable ? aucun path ne sera trouv�.");
}

if (startNode.walkable && targetNode.walkable)
{
Heap<Node> openSet = new Heap<Node>(grid.MaxSize);
Expand Down
101 changes: 101 additions & 0 deletions Unity_jeu/Assets/Liam_Composant/Scene 2/TargetWander.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using UnityEngine;
using System.Linq;

public class TargetWander : MonoBehaviour
{
[Header("R�f�rences")]
public Grid grid; // ton composant Grid (le m�me que pour le pathfinding)
public Transform seeker; // (optionnel) pour d�clencher un changement � l'arriv�e

[Header("Param�tres de d�placement")]
public float changeEverySeconds = 4f; // change la position � intervalle r�gulier
public float arriveDistance = 1.5f; // ou quand le seeker est proche
public float minMoveDistance = 4f; // �viter de re-piocher quasi la m�me case
public float yOffset = 0.5f; // hauteur du target

[Header("Qualit� des points")]
public int minFreeNeighbours = 2; // �vite les cul-de-sac trop serr�s
public int maxTries = 60; // essais max pour trouver une bonne case
public int penaltyMax = 999999; // tol�rance au "penalty" (plus petit = �vite bords/murs)

float _timer;

void Reset()
{
// petit confort si on pose le script sur le Target directement
grid = Object.FindFirstObjectByType<Grid>();
}

void OnEnable()
{
_timer = changeEverySeconds;
MoveTargetToRandomWalkable(forceFar: true);
}

void Update()
{
if (grid == null) return;

_timer -= Time.deltaTime;

// 1) changement p�riodique
if (_timer <= 0f)
{
MoveTargetToRandomWalkable();
_timer = changeEverySeconds;
}

// 2) ou quand le seeker arrive au point
if (seeker != null)
{
if ((seeker.position - transform.position).sqrMagnitude <= arriveDistance * arriveDistance)
{
MoveTargetToRandomWalkable();
_timer = changeEverySeconds; // on red�marre le timer
}
}
}

void MoveTargetToRandomWalkable(bool forceFar = false)
{
Vector2 size = grid.gridWorldSize;
Vector3 center = grid.transform.position;

Vector3 startPos = transform.position;
for (int i = 0; i < maxTries; i++)
{
float rx = Random.Range(-size.x * 0.5f, size.x * 0.5f);
float rz = Random.Range(-size.y * 0.5f, size.y * 0.5f);
Vector3 candidate = new Vector3(center.x + rx, startPos.y, center.z + rz);

Node n = grid.NodeFromWorldPoint(candidate);
if (!n.walkable) continue;
if (n.movementPenalty > penaltyMax) continue; // (facultatif) �viter les bords si tu mets des gros penalties

// �viter de rester coll� / cul-de-sac : au moins X voisins walkable
int free = grid.GetNeighbours(n).Count(nei => nei.walkable);
if (free < minFreeNeighbours) continue;

// garder une distance minimale pour varier la balade
if (forceFar || minMoveDistance > 0f)
{
float dSqr = (n.worldPosition - startPos).sqrMagnitude;
if (dSqr < minMoveDistance * minMoveDistance) continue;
}

transform.position = n.worldPosition + Vector3.up * yOffset;
return;
}

// fallback : poser quand m�me sur la meilleure estimation locale
Node fallback = grid.NodeFromWorldPoint(startPos);
transform.position = fallback.worldPosition + Vector3.up * yOffset;
}

void OnDrawGizmosSelected()
{
Gizmos.color = Color.yellow;
Gizmos.DrawWireSphere(transform.position, arriveDistance);
}
}

2 changes: 2 additions & 0 deletions Unity_jeu/Assets/Liam_Composant/Scene 2/TargetWander.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Unity_jeu/Assets/Liam_Composant/Scene 2/road.mat
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ Material:
- _WorkflowMode: 1
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 0.745283, g: 0.21444462, b: 0.63990414, a: 1}
- _Color: {r: 0.745283, g: 0.21444455, b: 0.6399041, a: 1}
- _BaseColor: {r: 0.44313726, g: 0.22745098, b: 0.15686275, a: 1}
- _Color: {r: 0.44313723, g: 0.22745094, b: 0.1568627, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
m_BuildTextureStacks: []
Expand Down
Loading