---
name: weapon-trail
description: Create a ribbon trail effect that follows a weapon's movement.
---

# Weapon Trail

Create a ribbon trail effect that follows a weapon's movement.

## Technique

Build a custom `BufferGeometry` that stores a history of positions in a ring buffer. Each frame, record the current world positions of trail points and update the geometry vertices to create a ribbon connecting all historical positions.

## Key Concepts

- Define trail points (e.g., base and tip of weapon)
- Use a ring buffer to store position history efficiently
- Create geometry with proper UVs for texture mapping (gradient fade)
- Update vertex positions each frame with `positions.needsUpdate = true`
- Use `localToWorld()` to get world positions from the target object
- Support enabling/disabling with fade out animation

## Usage

```tsx
const trailPoints = [new Vector3(0, 0, 0), new Vector3(0, 1.5, 0)]

<group ref={weaponRef}>
  <mesh>{/* weapon mesh */}</mesh>
</group>
<Trail target={weaponRef} points={trailPoints} enabled={isAttacking} />
```

## Geometry Structure

- Segments: historical snapshots (oldest to newest)
- Points per segment: trail point positions at that time
- UVs: u = position along trail (0-1), v = age (0 = newest, 1 = oldest)
- Alpha map texture for gradient fade effect

---

This skill is part of [verekia](https://x.com/verekia)'s [**r3f-gamedev**](https://github.com/verekia/r3f-gamedev).


---
Source attribution: verekia
Original project: https://github.com/verekia/r3f-gamedev/blob/1fec20bc549fb944374084b1a8c33b8ca5a927ef/skills/weapon-trail/SKILL.md
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 Verekia

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: verekia
Original project: https://github.com/verekia/r3f-gamedev/blob/1fec20bc549fb944374084b1a8c33b8ca5a927ef/skills/weapon-trail/SKILL.md
Attribution basis: Source repository record

Fields of work: Development & Engineering
Roles: Frontend Developer, Game Developer
Specialties: Cross Platform, Frontend
Tools: R3F Gamedev
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: a947ba9f88642a68cfd548201796f98e96a54b8e61a734dfecaad2c5049ce9e7
