improve movebg aim assist

This commit is contained in:
Demur Rumed 2025-08-16 16:07:40 +00:00
commit 8deea762ef
3 changed files with 17 additions and 15 deletions

View file

@ -2,7 +2,6 @@
#include "soh/OTRGlobals.h" #include "soh/OTRGlobals.h"
#include <map> #include <map>
#include <random>
#include <functions.h> #include <functions.h>
#include <macros.h> #include <macros.h>
@ -27,7 +26,6 @@ extern "C" {
#include "overlays/actors/ovl_En_Fz/z_en_fz.h" #include "overlays/actors/ovl_En_Fz/z_en_fz.h"
#include "overlays/actors/ovl_En_Ik/z_en_ik.h" #include "overlays/actors/ovl_En_Ik/z_en_ik.h"
#include "overlays/actors/ovl_En_G_Switch/z_en_g_switch.h" #include "overlays/actors/ovl_En_G_Switch/z_en_g_switch.h"
#include "overlays/actors/ovl_En_Ice_Hono/z_en_ice_hono.h"
#include "overlays/actors/ovl_En_Kakasi2/z_en_kakasi2.h" #include "overlays/actors/ovl_En_Kakasi2/z_en_kakasi2.h"
#include "overlays/actors/ovl_En_Wood02/z_en_wood02.h" #include "overlays/actors/ovl_En_Wood02/z_en_wood02.h"
#include "overlays/actors/ovl_En_Wonder_Item/z_en_wonder_item.h" #include "overlays/actors/ovl_En_Wonder_Item/z_en_wonder_item.h"
@ -456,7 +454,7 @@ void ActorAccessibility_InitActors() {
ActorAccessibility_InitPolicy(&policy, "Water Temple Hookshot Platform", [](AccessibleActor* actor) { ActorAccessibility_InitPolicy(&policy, "Water Temple Hookshot Platform", [](AccessibleActor* actor) {
if ((actor->frameCount & 31) == 0) { if ((actor->frameCount & 31) == 0) {
BgMizuMovebg* movebg = (BgMizuMovebg*)actor->actor; BgMizuMovebg* movebg = (BgMizuMovebg*)actor->actor;
if (MOVEBG_TYPE(actor->actor->params) < 4) { if (MOVEBG_TYPE(actor->actor->params) != 7) {
actor->policy.aimAssist.isProvider = 0; actor->policy.aimAssist.isProvider = 0;
} }
if (movebg->sfxFlags & 1) { if (movebg->sfxFlags & 1) {
@ -469,6 +467,7 @@ void ActorAccessibility_InitActors() {
}); });
policy.distance = 1000; policy.distance = 1000;
policy.ydist = 1000; policy.ydist = 1000;
policy.volume = 0.5;
policy.aimAssist.isProvider = AIM_HOOK; policy.aimAssist.isProvider = AIM_HOOK;
ActorAccessibility_AddSupportedActor(ACTOR_BG_MIZU_MOVEBG, policy); ActorAccessibility_AddSupportedActor(ACTOR_BG_MIZU_MOVEBG, policy);
ActorAccessibility_InitPolicy(&policy, "Scarecrow", NA_SE_IT_KAKASHI_JUMP); ActorAccessibility_InitPolicy(&policy, "Scarecrow", NA_SE_IT_KAKASHI_JUMP);
@ -520,9 +519,9 @@ void ActorAccessibility_InitActors() {
f32 zdist = fabs((player->actor.world.pos.x - actor->actor->world.pos.x) * velocityXRight + f32 zdist = fabs((player->actor.world.pos.x - actor->actor->world.pos.x) * velocityXRight +
(player->actor.world.pos.z - actor->actor->world.pos.z) * velocityZRight); (player->actor.world.pos.z - actor->actor->world.pos.z) * velocityZRight);
if ((xdist - size / 2) < 0) { if ((xdist - size / 2.0) < 0) {
ActorAccessibility_SetSoundPitch(actor, 0, 0.5); ActorAccessibility_SetSoundPitch(actor, 0, 0.5);
} else if ((xdist + size / 2) > 0 && zdist < size / 2 && xdist < 150.0) { } else if ((xdist + size / 2.0) > 0 && zdist < size / 2.0 && xdist < 150.0) {
ActorAccessibility_PlaySoundForActor(actor, 1, NA_SE_EV_DIAMOND_SWITCH); ActorAccessibility_PlaySoundForActor(actor, 1, NA_SE_EV_DIAMOND_SWITCH);
} }
}); });

View file

@ -1,7 +1,6 @@
#include <sstream> #include <sstream>
#include <unordered_set> #include <unordered_set>
#include <map> #include <map>
#include <random>
#include <vector> #include <vector>
#include "ActorAccessibility.h" #include "ActorAccessibility.h"
@ -17,7 +16,6 @@
#include "File.h" #include "File.h"
#include "soh/Enhancements/speechsynthesizer/SpeechSynthesizer.h" #include "soh/Enhancements/speechsynthesizer/SpeechSynthesizer.h"
#include "soh/Enhancements/tts/tts.h"
#include "soh/Enhancements/game-interactor/GameInteractor.h" #include "soh/Enhancements/game-interactor/GameInteractor.h"
#include "soh/ObjectExtension/ObjectExtension.h" #include "soh/ObjectExtension/ObjectExtension.h"
@ -737,8 +735,14 @@ AimAssistProps ActorAccessibility_ProvideAimAssistForActor(AccessibleActor* acto
angle = angle / -14000.0 * 16384; angle = angle / -14000.0 * 16384;
f32 cos_angle = Math_CosS(angle); f32 cos_angle = Math_CosS(angle);
f32 slope = cos_angle == 0.0f ? 0.0f : Math_SinS(angle) / cos_angle; f32 slope = cos_angle == 0.0f ? 0.0f : Math_SinS(angle) / cos_angle;
s32 yIntercept = slope * actor->xzDistToPlayer + player->actor.focus.pos.y; f32 x = actor->pos.x, z = actor->pos.z, xzDist = actor->xzDistToPlayer;
s32 yHeight = actor->pos.y + 25; s32 yHeight = actor->pos.y + 25;
if (actor->id == ACTOR_BG_MIZU_MOVEBG) {
x += Math_SinS(actor->actor->shape.rot.y) * 50;
z += Math_CosS(actor->actor->shape.rot.y) * 50;
xzDist = sqrtf(SQ(player->actor.world.pos.x - x) + SQ(player->actor.world.pos.z - z));
}
s32 yIntercept = slope * xzDist + player->actor.focus.pos.y;
AimAssistProps aimAssistProps; AimAssistProps aimAssistProps;
if (yIntercept > yHeight + 25) { if (yIntercept > yHeight + 25) {
aimAssistProps.pitch = 1.5; aimAssistProps.pitch = 1.5;
@ -757,8 +761,7 @@ AimAssistProps ActorAccessibility_ProvideAimAssistForActor(AccessibleActor* acto
} else { } else {
actor->aimFrequency = 1 + (uint8_t)(yDiff / 5); actor->aimFrequency = 1 + (uint8_t)(yDiff / 5);
} }
s16 yawdiff = s16 yawdiff = player->yaw - Math_Atan2S(z - player->actor.world.pos.z, x - player->actor.world.pos.x);
player->yaw - Math_Atan2S(actor->pos.z - player->actor.world.pos.z, actor->pos.x - player->actor.world.pos.x);
if (yawdiff > -0x1000 && yawdiff < 0x1000) { if (yawdiff > -0x1000 && yawdiff < 0x1000) {
aimAssistProps.volume = 1.0 - (yawdiff * yawdiff) / (float)0x2000000; aimAssistProps.volume = 1.0 - (yawdiff * yawdiff) / (float)0x2000000;
} else if (yawdiff > -0x2000 && yawdiff < 0x2000) { } else if (yawdiff > -0x2000 && yawdiff < 0x2000) {

View file

@ -23,9 +23,9 @@ struct ActorAccessibilityPolicy {
s16 sound; // The ID of a sound to play. Ignored if the callback is set. s16 sound; // The ID of a sound to play. Ignored if the callback is set.
bool runsAlways; // If set, then the distance policy is ignored. bool runsAlways; // If set, then the distance policy is ignored.
int n; // How often to run the callback in frames. u8 n; // How often to run callback in frames.
f32 distance; // Maximum xz distance from player before the actor should be considered out of range. f32 distance; // Maximum xz distance from player before actor should be considered out of range.
f32 ydist; // Maximum y distance from player before the actor should be considered out of range. f32 ydist; // Maximum y distance from player before actor should be considered out of range.
f32 pitch; f32 pitch;
f32 volume; f32 volume;
f32 pitchModifier; f32 pitchModifier;