Refactor NPC behavior and teleportation logic; enhance tile material properties

This commit is contained in:
2025-12-13 01:16:59 +01:00
parent 53de85a269
commit 189bbb7ae7
7 changed files with 66 additions and 22 deletions

View File

@@ -11,9 +11,10 @@ Material:
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3} m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
m_Parent: {fileID: 0} m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0 m_ModifiedSerializedProperties: 0
m_ValidKeywords: [] m_ValidKeywords:
- _EMISSION
m_InvalidKeywords: [] m_InvalidKeywords: []
m_LightmapFlags: 4 m_LightmapFlags: 6
m_EnableInstancingVariants: 0 m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0 m_DoubleSidedGI: 0
m_CustomRenderQueue: -1 m_CustomRenderQueue: -1
@@ -116,8 +117,8 @@ Material:
- _XRMotionVectorsPass: 1 - _XRMotionVectorsPass: 1
- _ZWrite: 1 - _ZWrite: 1
m_Colors: m_Colors:
- _BaseColor: {r: 1, g: 0.18039216, b: 0.3882353, a: 1} - _BaseColor: {r: 1, g: 1, b: 1, a: 1}
- _Color: {r: 1, g: 0.18039212, b: 0.38823527, a: 1} - _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1} - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
m_BuildTextureStacks: [] m_BuildTextureStacks: []

View File

@@ -677,12 +677,13 @@ MonoBehaviour:
tileBreakVfxPrefab: {fileID: 3395603910160708684, guid: 7c5c893ba21562b2aad6bffb1887f4b1, type: 3} tileBreakVfxPrefab: {fileID: 3395603910160708684, guid: 7c5c893ba21562b2aad6bffb1887f4b1, type: 3}
jumpPadPrefab: {fileID: 3258547662887829175, guid: e1d1bd44370c9986ebd4bb7730430a12, type: 3} jumpPadPrefab: {fileID: 3258547662887829175, guid: e1d1bd44370c9986ebd4bb7730430a12, type: 3}
teleporterPrefab: {fileID: 4601941687390792571, guid: 53f1de555c523511e9aaa1dee06fdf79, type: 3} teleporterPrefab: {fileID: 4601941687390792571, guid: 53f1de555c523511e9aaa1dee06fdf79, type: 3}
gridSizeX: 20 gridSizeX: 60
gridSizeY: 20 gridSizeY: 60
floorsCount: 3 floorsCount: 3
floorHeightDistance: 15 floorHeightDistance: 15
decayTime: 0.5 decayTime: 0.75
fallingTime: 2 fallingTime: 2
minimumDistanceBetweenTeleporters: 10
--- !u!114 &453022423 --- !u!114 &453022423
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@@ -7,7 +7,7 @@ namespace Core.Domain
public class GameSession public class GameSession
{ {
private const string HighScoreKey = "HighScore"; private const string HighScoreKey = "HighScore";
private const float NpcSpawnTime = 4f; private const float NpcSpawnTime = 30f;
private const float PowerUpSpawnInterval = 25f; private const float PowerUpSpawnInterval = 25f;
public int Score { get; private set; } public int Score { get; private set; }

View File

@@ -243,7 +243,7 @@ namespace Infrastructure.Unity
if (_playerInstance && hunterNpcPrefab && Random.value < 0.3f) if (_playerInstance && hunterNpcPrefab && Random.value < 0.3f)
{ {
var hunter = Instantiate(hunterNpcPrefab, spawnPos, Quaternion.identity); var hunter = Instantiate(hunterNpcPrefab, spawnPos, Quaternion.identity);
hunter.Initialize(_playerInstance); hunter.Initialize(_playerInstance, () => _gameSession.EndGame(), () => _gameSession.TimeDilation);
} }
else if (npcPrefab) else if (npcPrefab)
{ {

View File

@@ -1,3 +1,4 @@
using System;
using UnityEngine; using UnityEngine;
using KBCore.Refs; using KBCore.Refs;
@@ -12,28 +13,32 @@ namespace Infrastructure.Unity
[Self] [SerializeField] private Rigidbody rb; [Self] [SerializeField] private Rigidbody rb;
private PlayerController _target; private PlayerController _target;
private Action _onCaughtCallback;
private Func<float> _timeDilationProvider;
public void Initialize(PlayerController target) public void Initialize(PlayerController target, Action onCaughtCallback, Func<float> timeDilationProvider)
{ {
_target = target; _target = target;
_onCaughtCallback = onCaughtCallback;
_timeDilationProvider = timeDilationProvider;
} }
private void FixedUpdate() private void FixedUpdate()
{ {
if (_target == null) return; if (!_target) return;
var dilation = _timeDilationProvider?.Invoke() ?? 1f;
if (IsGrounded()) if (IsGrounded())
{ {
var direction = (_target.transform.position - transform.position).normalized; var direction = (_target.transform.position - transform.position).normalized;
// Flatten direction to avoid flying/digging
direction.y = 0; direction.y = 0;
direction.Normalize(); direction.Normalize();
rb.MovePosition(rb.position + direction * (moveSpeed * Time.fixedDeltaTime)); rb.MovePosition(rb.position + direction * (moveSpeed * dilation * Time.fixedDeltaTime));
} }
// Trigger tiles if (Physics.Raycast(transform.position, Vector3.down, out var hit, 2f, tileLayer))
if (Physics.Raycast(transform.position, Vector3.down, out var hit, 1.5f, tileLayer))
{ {
if (hit.collider.TryGetComponent<TileViewAdapter>(out var tile)) if (hit.collider.TryGetComponent<TileViewAdapter>(out var tile))
{ {
@@ -44,16 +49,26 @@ namespace Infrastructure.Unity
private bool IsGrounded() private bool IsGrounded()
{ {
return Physics.Raycast(transform.position, Vector3.down, out var hit, 1.15f, tileLayer); return Physics.Raycast(transform.position, Vector3.down, out var hit, 2f, tileLayer);
} }
private void OnDrawGizmos() private void OnDrawGizmos()
{ {
if (_target) if (!_target) return;
{
Gizmos.color = Color.red; Gizmos.color = Color.red;
Gizmos.DrawLine(transform.position, _target.transform.position); Gizmos.DrawLine(transform.position, _target.transform.position);
} }
private void OnCollisionEnter(Collision other)
{
if (!_target) return;
if (other.gameObject == _target.gameObject)
{
_onCaughtCallback?.Invoke();
Destroy(gameObject);
}
} }
} }
} }

View File

@@ -19,6 +19,7 @@ namespace Infrastructure.Unity
[SerializeField] private float floorHeightDistance = 15f; [SerializeField] private float floorHeightDistance = 15f;
[SerializeField] private float decayTime = 0.5f; [SerializeField] private float decayTime = 0.5f;
[SerializeField] private float fallingTime = 2.0f; [SerializeField] private float fallingTime = 2.0f;
[SerializeField] private float minimumDistanceBetweenTeleporters = 3f;
public float FloorHeightDistance => floorHeightDistance; public float FloorHeightDistance => floorHeightDistance;
public int FloorsCount => floorsCount; public int FloorsCount => floorsCount;
@@ -73,6 +74,24 @@ namespace Infrastructure.Unity
var posA = new Vector3(spotA.x - xOffset, yOffset + 0.6f, spotA.y - zOffset); var posA = new Vector3(spotA.x - xOffset, yOffset + 0.6f, spotA.y - zOffset);
var posB = new Vector3(spotB.x - xOffset, yOffset + 0.6f, spotB.y - zOffset); var posB = new Vector3(spotB.x - xOffset, yOffset + 0.6f, spotB.y - zOffset);
// check if positions are not too close
if (Vector3.Distance(posA, posB) < minimumDistanceBetweenTeleporters)
{
// find a new position for teleporter B
for (var i = 0; i < coordinates.Count; i++)
{
if (i == indexA) continue;
var newSpotB = coordinates[i];
var newPosB = new Vector3(newSpotB.x - xOffset, yOffset + 0.6f, newSpotB.y - zOffset);
if (Vector3.Distance(posA, newPosB) >= minimumDistanceBetweenTeleporters)
{
posB = newPosB;
break;
}
}
}
var telA = Instantiate(teleporterPrefab, posA, Quaternion.identity, transform); var telA = Instantiate(teleporterPrefab, posA, Quaternion.identity, transform);
var telB = Instantiate(teleporterPrefab, posB, Quaternion.identity, transform); var telB = Instantiate(teleporterPrefab, posB, Quaternion.identity, transform);

View File

@@ -17,6 +17,12 @@ namespace Infrastructure.Unity
private Vector3 _currentDir; private Vector3 _currentDir;
private float _timer; private float _timer;
private Func<float> _timeDilationProvider;
public void Initialize(Func<float> timeDilationProvider)
{
_timeDilationProvider = timeDilationProvider;
}
private void Awake() private void Awake()
{ {
@@ -35,9 +41,11 @@ namespace Infrastructure.Unity
private void FixedUpdate() private void FixedUpdate()
{ {
if (IsGrounded()) rb.MovePosition(rb.position + _currentDir * (moveSpeed * Time.fixedDeltaTime)); var dilation = _timeDilationProvider?.Invoke() ?? 1f;
if (Physics.Raycast(transform.position, Vector3.down, out var hit, 1.5f, tileLayer)) if (IsGrounded()) rb.MovePosition(rb.position + _currentDir * (moveSpeed * dilation * Time.fixedDeltaTime));
if (Physics.Raycast(transform.position, Vector3.down, out var hit, 2.0f, tileLayer))
{ {
if (hit.collider.TryGetComponent<TileViewAdapter>(out var tile)) if (hit.collider.TryGetComponent<TileViewAdapter>(out var tile))
{ {
@@ -48,7 +56,7 @@ namespace Infrastructure.Unity
private bool IsGrounded() private bool IsGrounded()
{ {
return Physics.Raycast(transform.position, Vector3.down, out var hit, 1.15f, tileLayer); return Physics.Raycast(transform.position, Vector3.down, out var hit, 2.0f, tileLayer);
} }
private void PickNewDirection() private void PickNewDirection()