fp: Orient sprite in direction of velocity

This commit is contained in:
doyle 2023-09-27 00:09:14 +10:00
parent a9fba6f01d
commit ffb2ec3ea3
2 changed files with 12 additions and 5 deletions

View File

@ -470,6 +470,10 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_PlatformInput *input, FP_Ga
action->next_state = FP_EntitySmoochieState_Run; action->next_state = FP_EntitySmoochieState_Run;
} }
} }
if (entity_has_velocity) {
action->next_state = FP_EntitySmoochieState_Run;
}
} break; } break;
case FP_EntitySmoochieState_AttackDown: { case FP_EntitySmoochieState_AttackDown: {
@ -681,6 +685,11 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
entity->direction = dir_vector.y > 0.f ? FP_GameDirection_Down : FP_GameDirection_Up; entity->direction = dir_vector.y > 0.f ? FP_GameDirection_Down : FP_GameDirection_Up;
} }
} }
} else {
if (entity->velocity.x)
entity->direction = entity->velocity.x > 0.f ? FP_GameDirection_Right : FP_GameDirection_Left;
else if (entity->velocity.y)
entity->direction = entity->velocity.y > 0.f ? FP_GameDirection_Down : FP_GameDirection_Up;
} }
// NOTE: Determine AI movement ============================================================= // NOTE: Determine AI movement =============================================================
@ -743,7 +752,7 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
// NOTE: We haven't arrived yet, calculate an acceleration vector to the waypoint // NOTE: We haven't arrived yet, calculate an acceleration vector to the waypoint
if (dist_to_waypoint_sq > DQN_SQUARED(arrival_threshold)) { if (dist_to_waypoint_sq > DQN_SQUARED(arrival_threshold)) {
Dqn_V2 entity_to_waypoint_norm = Dqn_V2_Normalise(entity_to_waypoint); Dqn_V2 entity_to_waypoint_norm = Dqn_V2_Normalise(entity_to_waypoint);
acceleration_meters_per_s = entity_to_waypoint_norm * 4.f; acceleration_meters_per_s = entity_to_waypoint_norm * 2.f;
break; break;
} }

View File

@ -345,11 +345,9 @@ static Dqn_V2 FP_Game_CalcEntityWorldPos(FP_Game const *game, FP_GameEntityHandl
if (!game) if (!game)
return result; return result;
for (FP_GameEntity const *entity = FP_Game_GetEntity(DQN_CAST(FP_Game *) game, handle); FP_GameEntity const *first = FP_Game_GetEntity(DQN_CAST(FP_Game *) game, handle);
entity != game->root_entity; for (FP_GameEntity const *entity = first; entity != game->root_entity; entity = entity->parent)
entity = entity->parent) {
result += entity->local_pos; result += entity->local_pos;
}
return result; return result;
} }