|
| 1 | +""" |
| 2 | +random_yaw — UEFN Toolbelt Community Plugin |
| 3 | +============================================ |
| 4 | +Randomizes only the yaw (Z-axis rotation) of selected actors. |
| 5 | +Useful for natural prop placement where you want random facing |
| 6 | +directions without touching pitch or roll. |
| 7 | +
|
| 8 | +Author: Ocean Bennett (https://github.com/undergroundrap) |
| 9 | +Version: 1.0.0 |
| 10 | +License: AGPL-3.0 |
| 11 | +""" |
| 12 | + |
| 13 | +import random |
| 14 | +import unreal |
| 15 | +from UEFN_Toolbelt.registry import register_tool |
| 16 | + |
| 17 | + |
| 18 | +@register_tool( |
| 19 | + name="random_yaw", |
| 20 | + category="Community", |
| 21 | + description="Randomize only the yaw (Z rotation) of selected actors. " |
| 22 | + "Preserves pitch and roll — ideal for natural prop variation.", |
| 23 | + tags=["randomize", "rotation", "props", "quick"], |
| 24 | +) |
| 25 | +def run(yaw_range: float = 360.0, **kwargs) -> dict: |
| 26 | + """ |
| 27 | + Args: |
| 28 | + yaw_range: Total arc to randomize within (default 360 = fully random). |
| 29 | + Use 45 to limit to ±22.5° from current facing. |
| 30 | + """ |
| 31 | + actors = unreal.EditorLevelLibrary.get_selected_level_actors() |
| 32 | + if not actors: |
| 33 | + return {"status": "error", "error": "No actors selected."} |
| 34 | + |
| 35 | + half = yaw_range / 2.0 |
| 36 | + count = 0 |
| 37 | + with unreal.ScopedEditorTransaction("random_yaw") as _: |
| 38 | + for actor in actors: |
| 39 | + rot = actor.get_actor_rotation() |
| 40 | + new_yaw = rot.yaw + random.uniform(-half, half) |
| 41 | + actor.set_actor_rotation( |
| 42 | + unreal.Rotator(rot.pitch, new_yaw, rot.roll), |
| 43 | + teleport_physics=True, |
| 44 | + ) |
| 45 | + count += 1 |
| 46 | + |
| 47 | + return {"status": "ok", "count": count, "yaw_range": yaw_range} |
0 commit comments