49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
using Sandbox;
|
|
|
|
public enum GravityType
|
|
{
|
|
Down,
|
|
Circle
|
|
}
|
|
public sealed class Teleporter : Component, Component.ITriggerListener
|
|
{
|
|
[Property] public GameObject ToPosGameObject { get; set; }
|
|
[Property] public GameObject Building { get; set; }
|
|
// [Property] public bool ResetGravity { get; set; } = false;
|
|
// [Property] public bool NormalGravity { get; set; } = true;
|
|
|
|
[Property] public GravityType gravityType { get; set; } = GravityType.Down;
|
|
|
|
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;
|
|
|
|
if ( gravityType == GravityType.Circle )
|
|
{
|
|
controller.OverrideGravity = Vector3.Zero;
|
|
}
|
|
|
|
if ( gravityType == GravityType.Down )
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|