codeAPI Reference
Door Component with IPressable Interface
Door Component with IPressable
Map entity door with animated open/close using curves and the IPressable interface.
CSHARP
namespace Facepunch;
public sealed class Door : Component, Component.IPressable
{
[Property] public Curve AnimationCurve { get; set; } =
new Curve(new Curve.Frame(0f, 0f), new Curve.Frame(1f, 1.0f));
[Property, Group("Sound")] public SoundEvent OpenSound { get; set; }
[Property, Group("Sound")] public SoundEvent LockedSound { get; set; }
[Property, Sync] public bool IsLocked { get; set; }
[Property, Range(0.0f, 90.0f)] public float TargetAngle { get; set; } = 90.0f;
public enum DoorState { Open, Opening, Closing, Closed }
[Sync] private DoorState _state { get; set; }
bool Component.IPressable.Press(Component.IPressable.Event e)
{
if (IsLocked)
{
PlaySound(LockedSound);
return false;
}
Toggle(e.Source);
return true;
}
}Key Features
- AnimationCurve for smooth motion between open/closed states
- Sync for networked door state replication
- IPressable interface for player interaction
- OpenAwayFromPlayer option for smart door opening direction
Was this helpful?