codeAPI Reference
s&box HydraulicEntity: Hydraulic piston
HydraulicEntity Component API Reference
HydraulicEntity is a Component that implements IPlayerControllable for hydraulic pistons. It controls a SliderJoint to extend/retract between min and max lengths. Supports manual control and animated modes with easing.
Type Signature
CSHARP
public class HydraulicEntity : Component, IPlayerControllable
{
[Property, Range(0, 100), ClientEditable] public float MinLength { get; set; } = 10f;
[Property, Range(0, 100), ClientEditable] public float MaxLength { get; set; } = 100f;
[Property, Range(0, 1), ClientEditable] public float Length { get; set; } = 0.5f;
[Property, Range(0, 1), ClientEditable] public float Speed { get; set; } = 0.25f;
[Property, Sync, ClientEditable] public ClientInput Push { get; set; }
[Property, Range(0, 1), ClientEditable] public float PushSpeed { get; set; } = 0.25f;
[Property, Sync, ClientEditable] public ClientInput Pull { get; set; }
[Property, Range(0, 1), ClientEditable] public float PullSpeed { get; set; } = 0.25f;
[Property, Sync, ClientEditable] public ClientInput Toggle { get; set; }
[Property, Sync, ClientEditable] public ClientInput Activate { get; set; }
[Property] public SliderJoint Joint { get; set; }
public enum EaseType { Linear, EaseIn, EaseOut, EaseInOut, Bounce }
public void SetActiveState(bool state);
}Properties
- float MinLength { get; set; } = 10f - Minimum hydraulic length (0-100)
- float MaxLength { get; set; } = 100f - Maximum hydraulic length (0-100)
- float Length { get; set; } = 0.5f - Current length (0-1 normalized)
- float Speed { get; set; } = 0.25f - Extension speed (0-1)
- ClientInput Push { get; set; } - Input to extend
- float PushSpeed { get; set; } = 0.25f - Push speed multiplier
- ClientInput Pull { get; set; } - Input to retract
- float PullSpeed { get; set; } = 0.25f - Pull speed multiplier
- ClientInput Toggle { get; set; } - Input to toggle between min/max
- ClientInput Activate { get; set; } - Input for analog control
- SliderJoint Joint { get; set; } - The physics joint to control
Animated Mode Properties
- bool Animated { get; set; } - Enable automatic animation
- float AnimationSpeed { get; set; } = 1.0f - Animation speed (0-10)
- EaseType EaseIn { get; set; } = EaseType.Linear - Ease in type
- EaseType EaseOut { get; set; } = EaseType.Linear - Ease out type
Methods
SetActiveState(bool state)
Sets the active state and toggles the OnEffect GameObject. Used for visual feedback.IPlayerControllable Implementation
- OnControl() - Handles Push, Pull, Toggle, and Activate inputs
- OnStartControl() - Empty
- OnEndControl() - Empty
Usage
CSHARP
// Create a hydraulic entity
var hydraulic = GameObject.Components.Create<HydraulicEntity>();
hydraulic.Joint = sliderJoint;
hydraulic.MinLength = 20f;
hydraulic.MaxLength = 80f;
hydraulic.Push = Input.Button("attack1");
hydraulic.Pull = Input.Button("attack2");Notes
- Length is clamped between 0 and 1
- Joint MinLength and MaxLength are updated based on Length
- Updates CapsuleCollider for trigger collision
- Updates SkinnedModelRenderer bones for procedural animation
- Animated mode uses Easing functions for smooth animation
- OnEffect GameObject is enabled when active
Was this helpful?