54 lines
1.6 KiB
C#
54 lines
1.6 KiB
C#
using UnityEngine;
|
|
using Jotunn.Managers;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
public class BatFormBehavior : MonoBehaviour
|
|
{
|
|
private Animator anim;
|
|
private AswidProgression.FormRules formRules;
|
|
|
|
public void Initialize(AswidProgression.FormRules rules)
|
|
{
|
|
this.formRules = rules;
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
anim = GetComponentInChildren<Animator>();
|
|
if (Player.m_localPlayer != null)
|
|
{
|
|
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(true);
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) return;
|
|
|
|
// Ensure flight remains on continuously
|
|
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(true);
|
|
|
|
// Sync Animator
|
|
if (anim != null)
|
|
{
|
|
Vector3 vel = Player.m_localPlayer.GetVelocity();
|
|
vel.y = 0f;
|
|
float speed = vel.magnitude;
|
|
|
|
// Bats don't necessarily have a complex animator like players,
|
|
// but if they do have a speed or flying parameter, we set it here.
|
|
anim.SetFloat("forward_speed", speed);
|
|
anim.SetBool("flying", true);
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (Player.m_localPlayer != null)
|
|
{
|
|
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(false);
|
|
}
|
|
}
|
|
}
|
|
}
|