example-grass/Eat Da Rich/Pig/Pig.cs

56 lines
1.1 KiB
C#
Raw Normal View History

2025-07-20 11:22:53 +00:00
using Godot;
using System.Collections;
using System.Collections.Generic;
using Godot.Collections;
namespace Rokojori
{
[GlobalClass,Tool]
public partial class Pig:Node
{
[Export]
public RigidBody3D rigidBody3D;
[Export]
public float speed = 5;
2025-07-22 14:08:35 +00:00
[Export]
public Smoothing rotationSmoothing;
[Export]
public Action onSpawn;
[Export]
public bool alive = true;
2025-07-20 11:22:53 +00:00
public override void _Process( double delta )
{
2025-07-22 14:08:35 +00:00
if ( Engine.IsEditorHint() )
2025-07-20 11:22:53 +00:00
{
2025-07-22 14:08:35 +00:00
return;
2025-07-20 11:22:53 +00:00
}
2025-07-22 14:08:35 +00:00
var player = Unique<Player>.Get();
2025-07-20 11:22:53 +00:00
if ( player == null )
{
return;
}
2025-07-22 14:08:35 +00:00
2025-07-20 11:22:53 +00:00
var direction = player.GlobalPosition - rigidBody3D.GlobalPosition;
direction.Y = 0;
direction = direction.Normalized() * speed;
rigidBody3D.GlobalPosition += direction;
2025-07-22 14:08:35 +00:00
2025-07-20 11:22:53 +00:00
rigidBody3D.LookAt( player.GlobalPosition );
2025-07-22 14:08:35 +00:00
var nextRotation = rigidBody3D.GetGlobalQuaternion();
var rotation = Smoothing.Apply( rotationSmoothing, nextRotation, (float)delta );
rigidBody3D.SetGlobalQuaternion( rotation );
2025-07-20 11:22:53 +00:00
}
2025-07-22 14:08:35 +00:00
2025-07-20 11:22:53 +00:00
}
}