Vector Wall Bug Fix code w.r.t wall

dev-main
Ali Sharoz 5 days ago
parent 11cc921c50
commit 6fdbf52440

@ -0,0 +1,14 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!134 &13400000
PhysicMaterial:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Bouncy
dynamicFriction: 0
staticFriction: 0
bounciness: 1
frictionCombine: 1
bounceCombine: 3

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0d12993c8fabfeb4e971a0197446a3ba
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 13400000
userData:
assetBundleName:
assetBundleVariant:

@ -95,7 +95,7 @@ BoxCollider:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9694722736535169}
m_Material: {fileID: 0}
m_Material: {fileID: 13400000, guid: 0d12993c8fabfeb4e971a0197446a3ba, type: 2}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
@ -103,11 +103,11 @@ BoxCollider:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 0
m_IsTrigger: 1
m_ProvidesContacts: 0
m_Enabled: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 1, y: 1, z: 1}
m_Size: {x: 1.15, y: 1, z: 3.5}
m_Center: {x: 0, y: 0, z: 0}
--- !u!208 &8921202503349013827
NavMeshObstacle:
@ -137,7 +137,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
m_Name:
m_EditorClassIdentifier:
GlobalObjectIdHash: 3892629208
GlobalObjectIdHash: 1554870052
InScenePlacedSourceGlobalObjectIdHash: 0
AlwaysReplicateAsRoot: 0
SynchronizeTransform: 1

@ -8896,7 +8896,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 1676734515771252668, guid: 0193228de87741d40a42e561901c9083, type: 3}
propertyPath: m_LocalRotation.x
value: 0.39434478
value: 0.3943448
objectReference: {fileID: 0}
- target: {fileID: 1676734515771252668, guid: 0193228de87741d40a42e561901c9083, type: 3}
propertyPath: m_LocalRotation.y
@ -9161,15 +9161,15 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 203267159508449512, guid: 36b3ee75677a1544191c0ddaaadd8140, type: 3}
propertyPath: m_LocalRotation.x
value: 0.3943448
value: 0.39434484
objectReference: {fileID: 0}
- target: {fileID: 203267159508449512, guid: 36b3ee75677a1544191c0ddaaadd8140, type: 3}
propertyPath: m_LocalRotation.y
value: 0.31044647
value: 0.3104465
objectReference: {fileID: 0}
- target: {fileID: 203267159508449512, guid: 36b3ee75677a1544191c0ddaaadd8140, type: 3}
propertyPath: m_LocalRotation.z
value: -0.14352977
value: -0.1435298
objectReference: {fileID: 0}
- target: {fileID: 203267159508449512, guid: 36b3ee75677a1544191c0ddaaadd8140, type: 3}
propertyPath: m_LocalEulerAnglesHint.x

@ -6,7 +6,7 @@ using Unity.BossRoom.Gameplay.GameplayObjects.Character;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using static Codice.Client.Common.WebApi.WebApiEndpoints;
//using static Codice.Client.Common.WebApi.WebApiEndpoints;
public class AbilitySystem : NetworkBehaviour
{
@ -66,18 +66,18 @@ public class AbilitySystem : NetworkBehaviour
if (Input.GetMouseButtonUp(0) && isWallPlacementStarted)
{
if (isValidPlacement)
//if (isValidPlacement)
{
UseActiveAbility(); // Place the wall when LMB is released
isWallPlacementStarted = false;
}
else
/*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.");
}
}*/
}
}
else
@ -121,11 +121,11 @@ public class AbilitySystem : NetworkBehaviour
//AliSharoz
isValidPlacement = IsPlacementValid(hit.point, wallIndicator.transform.rotation, playerLayer);
//var meshRenderer = wallIndicator.GetComponent<MeshRenderer>();
//if (meshRenderer != null)
//{
// meshRenderer.material = isValidPlacement ? validPlacementMaterial : invalidPlacementMaterial;
//}
/*var meshRenderer = wallIndicator.GetComponent<MeshRenderer>();
if (meshRenderer != null)
{
meshRenderer.material = isValidPlacement ? validPlacementMaterial : invalidPlacementMaterial;
}*/
}
}
@ -133,27 +133,25 @@ public class AbilitySystem : NetworkBehaviour
{
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out RaycastHit hit))
{
if (isValidPlacement)
//if (isValidPlacement)
{
wallSpawnPosition = hit.point; // Save spawn position
initialMousePosition = Input.mousePosition; // Store the initial mouse position on click
isWallPlacementStarted = true;
Debug.Log($"[AbilitySystem] Wall placement started at {wallSpawnPosition}");
}
else
/*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.");
Invoke(nameof(RepositionAgent), 0.5f);
}
}*/
}
}
public float searchRadius = 5f;
/*public float searchRadius = 5f;
private void RepositionAgent()
private void RepositionAgent()
{
Debug.Log("RepositionAgent()1");
//if (NavMesh.SamplePosition(currentPosition, out hit, 0.01f, NavMesh.AllAreas))
@ -180,7 +178,7 @@ public class AbilitySystem : NetworkBehaviour
//{
// Debug.LogWarning("No valid NavMesh point found near the agent!");
//}
}
}*/
private void RotateWallIndicator()
{
if (isWallPlacementStarted && wallIndicator != null)
@ -206,20 +204,20 @@ public class AbilitySystem : NetworkBehaviour
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;
//}
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);
}
}*/
}
}
}

@ -1,4 +1,5 @@
using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
@ -8,7 +9,8 @@ public class VectorFencePrefab : NetworkBehaviour
[Header("Fence Settings")]
public VectorFenceAbility Ability;
private NavMeshObstacle navMeshObstacle;
[SerializeField] private List<NavMeshAgent> m_Agents = new List<NavMeshAgent>();
[SerializeField] private float searchRadius = 5f;
private void Awake()
{
navMeshObstacle = GetComponent<NavMeshObstacle>();
@ -16,10 +18,34 @@ public class VectorFencePrefab : NetworkBehaviour
{
Debug.LogError("[VectorFencePrefab] NavMeshObstacle is missing on the prefab!");
}
transform.localScale = new Vector3(Ability.wallLength, 0, Ability.wallWidth); // Start with zero height
}
private void Start() => Invoke(nameof(RepositionAgents), 0.5f);
private void OnTriggerEnter(Collider other)
{
var agent = other.GetComponent<NavMeshAgent>();
if (agent && !m_Agents.Contains(agent)) m_Agents.Add(agent);
}
private void OnTriggerExit(Collider other)
{
var agent = other.GetComponent<NavMeshAgent>();
if (agent) m_Agents.Remove(agent);
}
private void RepositionAgents()
{
m_Agents.RemoveAll(agent => agent == null);
m_Agents.ForEach(agent =>
{
if (NavMesh.SamplePosition(agent.transform.position, out NavMeshHit hit, searchRadius, NavMesh.AllAreas))
agent.Warp(hit.position);
});
}
public override void OnNetworkSpawn()
{
if (IsServer)

Loading…
Cancel
Save