sasalka/Code/Gravity/Teleporter.cs
2025-05-25 19:14:50 +03:00

32 lines
905 B
C#

using Sandbox;
public sealed class Teleporter : Component, Component.ITriggerListener
{
[Property] public GameObject ToPosGameObject { get; set; }
[Property] public GameObject Building { get; set; }
public void OnTriggerEnter( Collider other )
{
var otherEntity = other.GameObject;
Log.Info($"{otherEntity.Name} Телепорт");
if (otherEntity.Components.TryGet<Dedugan>(out var controller))
{
Log.Info($"{otherEntity.Name} вошел в зону телепорта");
otherEntity.WorldPosition = ToPosGameObject.WorldPosition;
controller.OverrideGravity = Vector3.Down;
controller.EyeAngles = new Angles( 0, ToPosGameObject.WorldRotation.Yaw(), 0 ).ToRotation();
controller.Renderer.LocalRotation = new Angles( 0, ToPosGameObject.WorldRotation.Yaw(), 0 ).ToRotation();
if ( Building != null )
{
Building.Enabled = !Building.Enabled;
}
}
}
}