Working on slow down ability

main
Hazim Bin Ijaz 1 month ago
parent 1afc48072e
commit 671567bb81

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a56539f7f1d01564e96fc5270dbf94f7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,19 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e7350d0607d7cc46a92f7ff596ad88d, type: 3}
m_Name: SlowZoneAbility
m_EditorClassIdentifier:
abilityName: Slowdown Area
abilityKey: Slowdown
keybind: 113
cooldownTime: 3
slowZonePrefab: {fileID: 5818330108676053786, guid: 4979352732bf84b44a9c789bef80b18a, type: 3}

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

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ce2326204c1815d48a8b749dcea9caf2
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,122 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &5818330108676053786
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5066519206278508126}
- component: {fileID: 5158718991394562100}
- component: {fileID: 825873091886110301}
- component: {fileID: 8294231852451494523}
- component: {fileID: 7596904637393423818}
m_Layer: 0
m_Name: SlowDownZonePrefab
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &5066519206278508126
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5818330108676053786}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.5, y: 0.5, z: 0.5}
m_ConstrainProportionsScale: 1
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &5158718991394562100
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5818330108676053786}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &825873091886110301
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5818330108676053786}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 2758e3f8ea8e3644c85864c0cc87f779, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!114 &8294231852451494523
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5818330108676053786}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
m_Name:
m_EditorClassIdentifier:
GlobalObjectIdHash: 4101054131
InScenePlacedSourceGlobalObjectIdHash: 0
AlwaysReplicateAsRoot: 0
SynchronizeTransform: 1
ActiveSceneSynchronization: 0
SceneMigrationSynchronization: 1
SpawnWithObservers: 1
DontDestroyWithOwner: 0
AutoObjectParentSync: 1
--- !u!114 &7596904637393423818
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5818330108676053786}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 16c014692584a9a438b902616cc2dd35, type: 3}
m_Name:
m_EditorClassIdentifier:
zoneRadius: 5
slowDuration: 3

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 4979352732bf84b44a9c789bef80b18a
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -219,6 +219,9 @@ PrefabInstance:
- targetCorrespondingSourceObject: {fileID: 4600110157238723781, guid: 0d2d836e2e83b754fa1a1c4022d6d65d, type: 3} - targetCorrespondingSourceObject: {fileID: 4600110157238723781, guid: 0d2d836e2e83b754fa1a1c4022d6d65d, type: 3}
insertIndex: -1 insertIndex: -1
addedObject: {fileID: 4727018541459492655} addedObject: {fileID: 4727018541459492655}
- targetCorrespondingSourceObject: {fileID: 4600110157238723781, guid: 0d2d836e2e83b754fa1a1c4022d6d65d, type: 3}
insertIndex: -1
addedObject: {fileID: 7049454171559621213}
m_SourcePrefab: {fileID: 100100000, guid: 0d2d836e2e83b754fa1a1c4022d6d65d, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 0d2d836e2e83b754fa1a1c4022d6d65d, type: 3}
--- !u!114 &741733315856861890 stripped --- !u!114 &741733315856861890 stripped
MonoBehaviour: MonoBehaviour:
@ -287,6 +290,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
m_ServerCharacter: {fileID: 741733315856861890} m_ServerCharacter: {fileID: 741733315856861890}
m_PhysicsWrapper: {fileID: 6116655102486013040} m_PhysicsWrapper: {fileID: 6116655102486013040}
m_AbilitySystem: {fileID: 7049454171559621213}
--- !u!114 &4887850889182527394 --- !u!114 &4887850889182527394
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -649,6 +653,20 @@ Animator:
m_AllowConstantClipSamplingOptimization: 1 m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorStateOnDisable: 0 m_KeepAnimatorStateOnDisable: 0
m_WriteDefaultValuesOnDisable: 0 m_WriteDefaultValuesOnDisable: 0
--- !u!114 &7049454171559621213
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6009713983291384756}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9d1377d8a6afd7d4fbc33f3db37363bd, type: 3}
m_Name:
m_EditorClassIdentifier:
abilities:
- {fileID: 11400000, guid: e4794e2f71f66a74486c797344695ce7, type: 2}
--- !u!4 &6009713983291384766 stripped --- !u!4 &6009713983291384766 stripped
Transform: Transform:
m_CorrespondingSourceObject: {fileID: 4600110157238723791, guid: 0d2d836e2e83b754fa1a1c4022d6d65d, type: 3} m_CorrespondingSourceObject: {fileID: 4600110157238723791, guid: 0d2d836e2e83b754fa1a1c4022d6d65d, type: 3}

@ -294,8 +294,8 @@ GameObject:
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 286165427} - component: {fileID: 286165427}
- component: {fileID: 286165428}
- component: {fileID: 286165429} - component: {fileID: 286165429}
- component: {fileID: 286165428}
m_Layer: 0 m_Layer: 0
m_Name: Platforms m_Name: Platforms
m_TagString: Untagged m_TagString: Untagged
@ -379,7 +379,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 0
--- !u!4 &676920372 --- !u!4 &676920372
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1251,7 +1251,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 0 m_IsActive: 1
--- !u!4 &1463337823 --- !u!4 &1463337823
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

@ -0,0 +1,39 @@
using UnityEngine;
public abstract class Ability : ScriptableObject
{
[Header("Ability Settings")]
public string abilityName;
public string abilityKey;
public KeyCode keybind; // Key to activate the ability
public float cooldownTime; // Cooldown duration in seconds
private float lastActivationTime;
/// <summary>
/// Checks if the ability can be activated (e.g., not on cooldown).
/// </summary>
public bool CanActivate()
{
return Time.time >= lastActivationTime + cooldownTime;
}
/// <summary>
/// Invokes the ability.
/// </summary>
/// <param name="owner">The GameObject or player triggering this ability.</param>
public void TryActivate(GameObject owner)
{
if (CanActivate())
{
Activate(owner);
lastActivationTime = Time.time;
}
else
{
Debug.Log($"{abilityName} is on cooldown.");
}
}
protected abstract void Activate(GameObject owner); // Logic for the specific ability
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4d2f9f4fdfd486f409d0defeead4992f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,78 @@
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
public class AbilitySystem : MonoBehaviour
{
[Header("Assigned Abilities")]
public List<Ability> abilities = new List<Ability>();
private Ability activeAbility; // Tracks the currently active ability in "spawn mode"
private bool isAbilityActive = false;
void Update()
{
// If ability mode is active, listen for mouse input to activate ability
if (isAbilityActive && Input.GetMouseButtonDown(0))
{
UseActiveAbility();
ToggleAbilityMode(activeAbility);
}
}
/// <summary>
/// Activates ability by key (called externally).
/// </summary>
/// <param name="key">The key assigned to an ability.</param>
public void ActivateAbilityByKey(string key)
{
foreach (var ability in abilities)
{
if (ability.abilityKey == key)
{
ToggleAbilityMode(ability);
return;
}
}
Debug.LogWarning($"No ability assigned to key {key}.");
}
/// <summary>
/// Toggles the ability activation mode.
/// </summary>
/// <param name="ability">The ability to toggle.</param>
private void ToggleAbilityMode(Ability ability)
{
if (isAbilityActive && activeAbility == ability)
{
DeactivateAbilityMode();
}
else
{
ActivateAbilityMode(ability);
}
}
private void ActivateAbilityMode(Ability ability)
{
isAbilityActive = true;
activeAbility = ability;
Debug.Log($"Ability {ability.name} activated! Click to use.");
}
private void DeactivateAbilityMode()
{
isAbilityActive = false;
activeAbility = null;
Debug.Log("Ability mode deactivated.");
}
private void UseActiveAbility()
{
if (activeAbility != null)
{
activeAbility.TryActivate(gameObject);
DeactivateAbilityMode(); // Ability used, deactivate mode
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9d1377d8a6afd7d4fbc33f3db37363bd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -265,6 +265,7 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character
return characterClass.Speed; return characterClass.Speed;
} }
/// <summary> /// <summary>
/// Determines the appropriate MovementStatus for the character. The /// Determines the appropriate MovementStatus for the character. The
/// MovementStatus is used by the client code when animating the character. /// MovementStatus is used by the client code when animating the character.

@ -81,6 +81,8 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects
public Action DropActionPrototype => m_DropActionPrototype; public Action DropActionPrototype => m_DropActionPrototype;
public Action PickUpActionPrototype => m_PickUpActionPrototype; public Action PickUpActionPrototype => m_PickUpActionPrototype;
public string SlowDownAbilityKey = "Slowdown";
List<Action> m_AllActions; List<Action> m_AllActions;
public Action GetActionPrototypeByID(ActionID index) public Action GetActionPrototypeByID(ActionID index)

@ -0,0 +1,35 @@
using UnityEngine;
using Unity.Netcode;
[CreateAssetMenu(menuName = "Abilities/Slow Zone Ability")]
public class SlowZoneAbility : Ability
{
[Header("Slow Zone Settings")]
public GameObject slowZonePrefab;
protected override void Activate(GameObject owner)
{
Camera mainCamera = Camera.main;
Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out RaycastHit hit))
{
Vector3 spawnPosition = hit.point;
if (owner.TryGetComponent(out NetworkObject networkOwner))
{
SpawnSlowZoneServerRpc(spawnPosition);
}
}
}
[Rpc(SendTo.Server)]
private void SpawnSlowZoneServerRpc(Vector3 position)
{
GameObject slowZone = Instantiate(slowZonePrefab, position, Quaternion.identity);
slowZone.GetComponent<NetworkObject>().Spawn();
Debug.Log($"Slow Zone spawned at {position}.");
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4e7350d0607d7cc46a92f7ff596ad88d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,72 @@
using System.Collections;
using System.Collections.Generic;
using Unity.BossRoom.Gameplay.GameplayObjects.Character;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
public class SlowZonePrefab : NetworkBehaviour
{
[Header("Slow Zone Settings")]
public float zoneRadius = 5f; // Radius of the slow zone
public float slowDuration = 3f; // Duration of the slow effect
private void Start()
{
// Start the process to slow down players when the zone is spawned
StartCoroutine(ApplySlowEffect());
}
private IEnumerator ApplySlowEffect()
{
// Run the logic once immediately
ApplySlowToPlayers();
// Optionally, repeat the check while the zone exists
yield return new WaitForSeconds(slowDuration);
// Destroy the zone after applying the slow effect
Destroy(gameObject);
}
private void ApplySlowToPlayers()
{
// Find all colliders in the zone
Collider[] hitColliders = Physics.OverlapSphere(transform.position, zoneRadius);
foreach (var collider in hitColliders)
{
if (collider.TryGetComponent<ServerCharacter>(out var player))
{
// Check if the player is NOT the crow
if (!player.IsCrow)
{
// Apply slow effect
StartCoroutine(SlowPlayer(player));
Debug.Log($"{player.name} is slowed down!");
}
}
}
}
private IEnumerator SlowPlayer(ServerCharacter player)
{
// Halve the player's movement speed
player.GetComponent<NavMeshAgent>().speed /= 2;
// player.Movement.SetMovementSpeed(originalSpeed * slowMultiplier);
// Wait for the slow duration
yield return new WaitForSeconds(slowDuration);
// Restore the original speed
player.GetComponent<NavMeshAgent>().speed /= 2;
Debug.Log($"{player.name}'s speed is restored.");
Destroy(gameObject);
}
// Debug visualization for the slow zone in the editor
private void OnDrawGizmos()
{
Gizmos.color = Color.cyan;
Gizmos.DrawWireSphere(transform.position, zoneRadius);
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 16c014692584a9a438b902616cc2dd35
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -8,6 +8,7 @@ using UnityEngine;
using UnityEngine.AI; using UnityEngine.AI;
using UnityEngine.Assertions; using UnityEngine.Assertions;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.Serialization;
namespace Unity.BossRoom.Gameplay.UserInput namespace Unity.BossRoom.Gameplay.UserInput
{ {
@ -117,6 +118,8 @@ namespace Unity.BossRoom.Gameplay.UserInput
public System.Action action1ModifiedCallback; public System.Action action1ModifiedCallback;
public AbilitySystem m_AbilitySystem;
ServerCharacter m_TargetServerCharacter; ServerCharacter m_TargetServerCharacter;
void Awake() void Awake()
@ -515,7 +518,17 @@ namespace Unity.BossRoom.Gameplay.UserInput
{ {
RequestAction(GameDataSource.Instance.Emote4ActionPrototype.ActionID, SkillTriggerStyle.Keyboard); RequestAction(GameDataSource.Instance.Emote4ActionPrototype.ActionID, SkillTriggerStyle.Keyboard);
} }
if (Input.GetKeyDown(KeyCode.Q))
{
if (m_ServerCharacter.IsCrow) // Ensure only the crow can activate the ability
{
m_AbilitySystem.ActivateAbilityByKey(GameDataSource.Instance.SlowDownAbilityKey);
}
else
{
Debug.Log("You must be the Crow to activate this ability.");
}
}
if (!EventSystem.current.IsPointerOverGameObject() && m_CurrentSkillInput == null) if (!EventSystem.current.IsPointerOverGameObject() && m_CurrentSkillInput == null)
{ {
//IsPointerOverGameObject() is a simple way to determine if the mouse is over a UI element. If it is, we don't perform mouse input logic, //IsPointerOverGameObject() is a simple way to determine if the mouse is over a UI element. If it is, we don't perform mouse input logic,

Loading…
Cancel
Save