VIRTUOS_Docs/sites/codesnippets/Slicegame.qmd
2026-01-07 22:07:11 +01:00

29 lines
2.1 KiB
Text

---
title: "Slicegame"
lightbox: true
---
---
The Slicegame is my attempt at implementing a [Beatsaber](https://beatsaber.com/)-Style Rhythm-Game. It explores Unreals Harmonix Plugin for parsing Midi in Metasounds and Geometry Script for real time boolean operations.
Given a Midi File, the system in `BP_DynamicObjectSpawner` spawns instances from the class `BP_DynamicHitObject` (the thing you want to hit) on a 3x3 Grid, moves them towards a location over time so it's always at to correct location (PlayerPosition + ArmLength) on the beat. The Midi also encodes from which direction the HitObject should be hit which saved in an Enum in the class during spawn.
![Midi Setup in Reaper](../../img/Midi.png)
Correct Hit detection to me several approaches, its a bit tricky because while our objects (or rather their hit indictors) don't move relative to the character, their angle to the player does change when the objects move from front to back while the player forwards or sideways. The hit detection therefore needs to take the characters view vector into account. From there, you can create up and right vectors and compare them direction of the sword via the dot product.
In Class : `BP_DynamicHitObject` | Function: `GetHitType`
```{=html}
<iframe width="100%" height="500" src="https://blueprintue.com/render/kxu6x76k/" scrolling="no" allowfullscreen></iframe>
```
As both velocity (sword is wiggly) and impact normal (surface doesn't always point in hit direction) vectors you can get from the hit event turned out to be rather unreliable for detection sword direction, I went with sampling the impact point on hit, attaching that point to the sword by converting the location into the relative space of the sword. After a short delay, that point, virtually attached to sword, has moved. By converting that point back to world transform, we can calculate the direction by subtracting hit location and delay sampled location. This works quite reliably.
In Class : `BP_DynamicHitObject`
```{=html}
<iframe width="100%" height="500" src="https://blueprintue.com/render/1g36zapg/" scrolling="no" allowfullscreen></iframe>
```