56 lines
1.1 KiB
C#
56 lines
1.1 KiB
C#
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;
|
|
|
|
[Export]
|
|
public Smoothing rotationSmoothing;
|
|
|
|
[Export]
|
|
public Action onSpawn;
|
|
|
|
[Export]
|
|
public bool alive = true;
|
|
|
|
public override void _Process( double delta )
|
|
{
|
|
if ( Engine.IsEditorHint() )
|
|
{
|
|
return;
|
|
}
|
|
|
|
var player = Unique<Player>.Get();
|
|
|
|
if ( player == null )
|
|
{
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
var direction = player.GlobalPosition - rigidBody3D.GlobalPosition;
|
|
direction.Y = 0;
|
|
|
|
direction = direction.Normalized() * speed;
|
|
|
|
rigidBody3D.GlobalPosition += direction;
|
|
|
|
rigidBody3D.LookAt( player.GlobalPosition );
|
|
var nextRotation = rigidBody3D.GetGlobalQuaternion();
|
|
var rotation = Smoothing.Apply( rotationSmoothing, nextRotation, (float)delta );
|
|
rigidBody3D.SetGlobalQuaternion( rotation );
|
|
}
|
|
|
|
}
|
|
} |