From c3b2b18f59378ce288c1fa5e4397b81a8c28a0f6 Mon Sep 17 00:00:00 2001 From: Hazim Bin Ijaz Date: Fri, 24 Jan 2025 18:52:43 +0500 Subject: [PATCH] Update AbilitySystem.cs --- Assets/Scripts/Gameplay/AbilitySystem.cs | 89 ++---------------------- 1 file changed, 7 insertions(+), 82 deletions(-) diff --git a/Assets/Scripts/Gameplay/AbilitySystem.cs b/Assets/Scripts/Gameplay/AbilitySystem.cs index 08ed9fd..1c60c78 100644 --- a/Assets/Scripts/Gameplay/AbilitySystem.cs +++ b/Assets/Scripts/Gameplay/AbilitySystem.cs @@ -73,18 +73,8 @@ public class AbilitySystem : NetworkBehaviour if (Input.GetMouseButtonUp(0) && isWallPlacementStarted) { - //if (isValidPlacement) - { - UseActiveAbility(); // Place the wall when LMB is released - isWallPlacementStarted = false; - } - /*else - { - UseActiveAbility(); // Place the wall when LMB is released - isWallPlacementStarted = false; - Invoke(nameof(RepositionAgent), 0.5f); - Debug.Log("Invalid placement! Cannot place wall on top of another player."); - }*/ + UseActiveAbility(); // Place the wall when LMB is released + isWallPlacementStarted = false; } } else @@ -124,16 +114,7 @@ public class AbilitySystem : NetworkBehaviour { //wallIndicator.transform.position = hit.point; // Update position to follow the mouse wallIndicator.transform.position = new Vector3(hit.point.x, 0, hit.point.z); - - //isValidPlacement = true; - //AliSharoz isValidPlacement = IsPlacementValid(hit.point, wallIndicator.transform.rotation, playerLayer); - - /*var meshRenderer = wallIndicator.GetComponent(); - if (meshRenderer != null) - { - meshRenderer.material = isValidPlacement ? validPlacementMaterial : invalidPlacementMaterial; - }*/ } } @@ -141,52 +122,13 @@ public class AbilitySystem : NetworkBehaviour { if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out RaycastHit hit)) { - //if (isValidPlacement) - { - wallSpawnPosition = new Vector3(hit.point.x, 0, hit.point.z); // Save spawn position - initialMousePosition = Input.mousePosition; // Store the initial mouse position on click - isWallPlacementStarted = true; - Debug.Log($"[AbilitySystem] Wall placement started at {wallSpawnPosition}"); - } - /*else - { - wallSpawnPosition = hit.point; // Save spawn position - initialMousePosition = Input.mousePosition; // Store the initial mouse position on click - isWallPlacementStarted = true; - Debug.Log("Cannot place the wall on top of another player."); - }*/ + wallSpawnPosition = new Vector3(hit.point.x, 0, hit.point.z); // Save spawn position + initialMousePosition = Input.mousePosition; // Store the initial mouse position on click + isWallPlacementStarted = true; + Debug.Log($"[AbilitySystem] Wall placement started at {wallSpawnPosition}"); + } } - /*public float searchRadius = 5f; - - private void RepositionAgent() - { - Debug.Log("RepositionAgent()1"); - //if (NavMesh.SamplePosition(currentPosition, out hit, 0.01f, NavMesh.AllAreas)) - //if (m_Agent.isOnNavMesh == false) - { - Debug.Log("RepositionAgent()2"); - Vector3 currentPosition = m_Agent.transform.position; - NavMeshHit hit; - - // Sample the nearest point on the NavMesh - if (NavMesh.SamplePosition(currentPosition, out hit, searchRadius, NavMesh.AllAreas)) - { - Debug.Log("RepositionAgent()3"); - Debug.Log($"Found nearest NavMesh point at {hit.position}"); - m_Agent.Warp(hit.position); // Warp the agent to the nearest point without path recalculation - } - else - { - Debug.Log("RepositionAgent()4"); - Debug.LogError("No walkable NavMesh point found within the search radius!"); - } - } - //else - //{ - // Debug.LogWarning("No valid NavMesh point found near the agent!"); - //} - }*/ private void RotateWallIndicator() { if (isWallPlacementStarted && wallIndicator != null) @@ -208,26 +150,9 @@ public class AbilitySystem : NetworkBehaviour angle -= 90f; Quaternion targetRotation = Quaternion.Euler(0f, angle, 0f); - // Smooth rotation with Lerp - // wallIndicator.transform.rotation = targetRotation; wallIndicator.transform.rotation = Quaternion.Lerp(wallIndicator.transform.rotation, targetRotation, 0.5f); - //wallIndicator.transform.rotation = Quaternion.Lerp(wallIndicator.transform.rotation, targetRotation, Time.deltaTime * wallRotationSpeed); isValidPlacement = IsPlacementValid(wallIndicator.transform.position, wallIndicator.transform.rotation, playerLayer); - /* - // Change indicator color based on placement validity - AliSharoz - var meshRenderer = wallIndicator.GetComponent(); - if (meshRenderer != null) - { - meshRenderer.material = isValidPlacement ? validPlacementMaterial : invalidPlacementMaterial; - } - - if (!isValidPlacement) - { - Debug.Log("Cannot rotate wall here: Overlapping with another object."); - Invoke(nameof(RepositionAgent), 0.5f); - }*/ } } }