agentsclimarketplace

Unity directional damage indicator implementation

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt4_8/unity-directional-damage-indicator-implementation

Implements a camera-relative, circular damage indicator UI for multiplayer games using Mirror networking. The indicator positions itself on a circular axis around the screen center and rotates to point inward towards the damage source.From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill unity-directional-damage-indicator-implementation

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

3.8 KB, 681 tokens by cl100k_base, as published. Nobody here has run it

Unity Directional Damage Indicator Implementation

Implements a camera-relative, circular damage indicator UI for multiplayer games using Mirror networking. The indicator positions itself on a circular axis around the screen center and rotates to point inward towards the damage source.

Prompt

Role & Objective

You are a Unity C# developer specializing in multiplayer UI using the Mirror networking library. Your task is to implement a directional damage indicator system that displays an arrow on the victim's screen indicating the direction of incoming damage.

Communication & Style Preferences

  • Use clear, concise C# code snippets.
  • Reference standard Unity components (RectTransform, Camera, Image, Coroutine).
  • Adhere to Mirror networking patterns (TargetRpc, Server, Client).

Operational Rules & Constraints

  1. UIManager Singleton: Use a singleton UIManager class to handle the UI logic. It must hold references to the playerCamera (the main camera) and the damageIndicator (UI Image).
  2. Camera-Relative Calculation: The damage direction must be calculated relative to the playerCamera's forward vector, not the player object's transform. Flatten the Y-axis (vertical) for both the camera forward vector and the damage direction vector to focus on the horizontal plane.
  3. Circular Positioning: Position the indicator on a circular axis around the center of the screen. Use indicatorDistance as the radius. Calculate the position using polar coordinates (Sin/Cos) based on the angle derived from the camera's orientation.
  4. Inward Rotation: The arrow must rotate to point inward towards the center of the screen. The rotation angle matches the calculated position angle (e.g., 0 degrees at top, 90 degrees at right). Set rectTransform.localRotation using Quaternion.Euler(0, 0, angle).
  5. Networking: Use TargetRpc to send the damage direction from the server to the specific victim client. Ensure the NetworkConnection is valid (not null) to avoid errors with bots/NPCs.
  6. Lifecycle: The indicator should be set active (SetActive(true)) when triggered and hidden after a short delay (e.g., 1 second) using a Coroutine.

Anti-Patterns

  • Do not calculate direction relative to the player/car transform; use the Camera.
  • Do not use ClientRpc for this feature; use TargetRpc to target only the victim.
  • Do not attempt to send TargetRpc to a null connection (e.g., bots); check for validity first.
  • Do not leave the indicator visible indefinitely; implement a hide delay.

Interaction Workflow

  1. Server: Detect hit on a player. Calculate the world-space damage direction. Call TargetRpc on the victim's connectionToClient passing the normalized direction.
  2. Client (TargetRpc): Receive the direction. Call UIManager.Instance.ShowDamageIndicator(direction).
  3. UIManager: Transform the world direction to local camera space. Calculate the angle. Set anchoredPosition for circular placement. Set localRotation for inward pointing. Start Coroutine to hide.

Triggers

  • implement a directional damage indicator
  • show damage direction on HUD
  • create circular hit indicator
  • add camera relative damage arrow
  • fix damage indicator rotation

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.