GodotComponentTest/entities/Player.cs

25 lines
594 B
C#
Raw Normal View History

2022-12-02 21:09:40 +01:00
using Godot;
using System;
public class Player : KinematicBody
{
2022-12-04 20:51:02 +01:00
private MovableComponent _movable;
2022-12-02 21:09:40 +01:00
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
2022-12-04 20:51:02 +01:00
_movable = GetNode<MovableComponent>("Movable");
if (_movable != null)
{
_movable.Connect("PositionUpdated", this, nameof(OnPositionUpdated));
}
2022-12-02 21:09:40 +01:00
}
2022-12-04 20:51:02 +01:00
private void OnPositionUpdated(Vector3 newPosition)
{
Transform transform = Transform;
transform.origin = newPosition;
Transform = transform;
}
2022-12-02 21:09:40 +01:00
}