GodotComponentTest/entities/Player.cs

25 lines
594 B
C#

using Godot;
using System;
public class Player : KinematicBody
{
private MovableComponent _movable;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
_movable = GetNode<MovableComponent>("Movable");
if (_movable != null)
{
_movable.Connect("PositionUpdated", this, nameof(OnPositionUpdated));
}
}
private void OnPositionUpdated(Vector3 newPosition)
{
Transform transform = Transform;
transform.origin = newPosition;
Transform = transform;
}
}