Update AbilitySystem.cs

dev-hazim
Hazim Bin Ijaz 1 week ago
parent fd88a7aa19
commit c3b2b18f59

@ -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<MeshRenderer>();
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<MeshRenderer>();
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);
}*/
}
}
}

Loading…
Cancel
Save