Skip to content

Commit

Permalink
Rework monster animation code #73: monster follows attacker
Browse files Browse the repository at this point in the history
  • Loading branch information
demoth committed Sep 11, 2023
1 parent 516fe4a commit 51508e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions game/src/main/java/jake2/game/GameCombat.java
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ public static void T_Damage(SubgameEntity target, SubgameEntity inflictor, Subga
SpawnDamage(sparks, point, normal, received, gameExports);

if (target.character != null) {
target.enemy = attacker; // todo
target.character.reactToDamage(damage);
return;
}
Expand Down
15 changes: 11 additions & 4 deletions game/src/main/kotlin/jake2/game/character/GameCharacter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ class GameCharacter(
TODO()
}

fun walk() {
fun walk(yaw: Float) {
if (stateMachine.attemptStateChange("walk")) {
M.M_walkmove(self, self.s.angles[Defines.YAW], 5f, game)
M.M_walkmove(self, yaw, 5f, game)
}
}

Expand Down Expand Up @@ -209,9 +209,16 @@ fun spawnNewMonster(self: SubgameEntity, game: GameExportsImpl) {

self.controller = selector(
sequence(
node { self.character.health < 50 },
node { self.enemy != null },
node {
val distance = floatArrayOf(0f, 0f, 0f)
Math3D.VectorSubtract(self.enemy.s.origin, self.s.origin, distance)
val enemy_yaw = Math3D.vectoyaw(distance)
self.ideal_yaw = enemy_yaw
true
},
finish {
self.character.walk()
self.character.walk(self.ideal_yaw)
}
),
sequence(
Expand Down

0 comments on commit 51508e0

Please sign in to comment.