Skip to content

Commit

Permalink
fixed enemy teleport to current enemy when possess
Browse files Browse the repository at this point in the history
  • Loading branch information
LTYGUY committed Feb 12, 2024
1 parent 8163e12 commit c03835c
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lc-hax/Scripts/Modules/Possession/PossessionMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ internal sealed class PossessionMod : MonoBehaviour {
Possession Possession { get; } = new();
Coroutine? UpdateCoroutine { get; set; } = null;
CharacterMovement? CharacterMovement { get; set; } = null;
KeyboardMovement? Keyboard { get; set; } = null;
MousePan? MousePan { get; set; } = null;

bool FirstUpdate { get; set; } = true;
Expand All @@ -35,7 +34,6 @@ internal sealed class PossessionMod : MonoBehaviour {

void Awake() {
this.CharacterMovement = this.gameObject.AddComponent<CharacterMovement>();
this.Keyboard = this.gameObject.AddComponent<KeyboardMovement>();
this.MousePan = this.gameObject.AddComponent<MousePan>();
this.enabled = false;

Expand Down Expand Up @@ -82,11 +80,9 @@ void ToggleNoClip() {
void UpdateComponentsOnCurrentState(bool thisGameObjectIsEnabled) {
if (this.MousePan is not MousePan mousePan) return;
if (this.CharacterMovement is not CharacterMovement rigidbodyKeyboard) return;
if (this.Keyboard is not KeyboardMovement keyboard) return;

mousePan.enabled = thisGameObjectIsEnabled;
rigidbodyKeyboard.enabled = !this.NoClipEnabled;
keyboard.enabled = this.NoClipEnabled;
}

IEnumerator EndOfFrameCoroutine() {
Expand Down Expand Up @@ -119,9 +115,10 @@ void EndOfFrameUpdate() {
agent.updatePosition = false;
agent.updateRotation = false;
}

characterMovement.Init();
characterMovement.enabled = false;
this.transform.position = enemy.transform.position;
characterMovement.enabled = true;
characterMovement.Init();
this.UpdateComponentsOnCurrentState(true);
}

Expand Down Expand Up @@ -163,8 +160,8 @@ void SetEnemyColliders(EnemyAI enemy, bool enabled) =>
internal void Possess(EnemyAI enemy) {
this.Unpossess();

this.Possession.SetEnemy(enemy);
this.FirstUpdate = true;
this.Possession.SetEnemy(enemy);
}

// Releases possession of the current enemy
Expand Down

0 comments on commit c03835c

Please sign in to comment.