upd
This commit is contained in:
54
Code/Gravity/InteractTeleporter.cs
Normal file
54
Code/Gravity/InteractTeleporter.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
namespace Sandbox.Gravity;
|
||||
|
||||
public sealed class InteractTeleporter : Component, Component.ITriggerListener
|
||||
{
|
||||
[Property] public GameObject ToPosGameObject { get; set; }
|
||||
|
||||
[Property, Sync] public List<Dedugan> Players { get; set; } = new();
|
||||
|
||||
public void OnTriggerEnter( Collider other )
|
||||
{
|
||||
var otherEntity = other.GameObject;
|
||||
if ( otherEntity.Components.TryGet<Dedugan>( out var controller ) )
|
||||
{
|
||||
Players.Add( controller );
|
||||
}
|
||||
}
|
||||
|
||||
public void OnTriggerExit( Collider other )
|
||||
{
|
||||
var otherEntity = other.GameObject;
|
||||
|
||||
if ( otherEntity.Components.TryGet<Dedugan>( out var controller ) )
|
||||
{
|
||||
Players.Remove( controller );
|
||||
}
|
||||
}
|
||||
|
||||
public void TeleportAll()
|
||||
{
|
||||
foreach ( var controller in Players )
|
||||
{
|
||||
Teleport( controller );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Rpc.Broadcast]
|
||||
public void Teleport( Dedugan controller )
|
||||
{
|
||||
controller.OverrideGravity = WorldRotation.Down;
|
||||
controller.GameObject.WorldPosition = ToPosGameObject.WorldPosition;
|
||||
controller.EyeAngles = new Angles( 0, ToPosGameObject.WorldRotation.Yaw(), 0 ).ToRotation();
|
||||
controller.Renderer.LocalRotation = new Angles( 0, ToPosGameObject.WorldRotation.Yaw(), 0 ).ToRotation();
|
||||
}
|
||||
|
||||
[Rpc.Broadcast]
|
||||
public void Teleport( Dedugan controller, Vector3 toPos )
|
||||
{
|
||||
controller.OverrideGravity = WorldRotation.Down;
|
||||
controller.GameObject.WorldPosition = toPos;
|
||||
controller.EyeAngles = new Angles( 0, ToPosGameObject.WorldRotation.Yaw(), 0 ).ToRotation();
|
||||
controller.Renderer.LocalRotation = new Angles( 0, ToPosGameObject.WorldRotation.Yaw(), 0 ).ToRotation();
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,6 @@ public sealed class Teleporter : Component, Component.ITriggerListener
|
||||
// [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 )
|
||||
|
||||
Reference in New Issue
Block a user