nordic2025/scripts/Mouth.cs
2025-04-05 16:29:54 +02:00

48 lines
763 B
C#

using Godot;
public partial class Mouth : XRCamera3D
{
[Export]
public float MaxEatWeight = 1.0f;
[Export]
public float EatGrowthFactor = 0.1f;
[Export]
public XRHand RightHand;
[Export]
public XRHand LeftHand;
public override void _Ready()
{
UpdateWeights();
}
public void EnterMouth(Node node)
{
try
{
RigidBody3D body = (RigidBody3D)node;
if (body.Mass > MaxEatWeight)
return;
UpdateWeights(body.Mass);
}
catch (System.InvalidCastException)
{
// dont give a shit
}
}
void UpdateWeights(float mass = 0f)
{
MaxEatWeight += (mass / MaxEatWeight) * EatGrowthFactor;
((XROrigin3D)GetParent()).WorldScale = 1.0f / MaxEatWeight;
RightHand.Strength = MaxEatWeight;
LeftHand.Strength = MaxEatWeight;
}
}