Embeddable
A class in Root.Township, the global namespace.
Lets a pointed item (arrow, knife, spear) stick into what it hits and parents it there, saved across restarts. The server decides when it embeds; clients follow a synced message. Get it with GetComponent<Embeddable>() on the item.
- Listed in Global namespace: E to H
- Inherits or implements
NetworkEntityBehaviour,ISavable<EmbeddableSaveData>,ISavableSave<EmbeddableSaveData>,ISavableSaveBase,IToolHitDependant - Derived types
EmbeddableEvent,EmbeddableSaveData,EmbeddableUnityEvent - Attributes
SavingInfo
Constructors
| Member | What it is |
|---|---|
Embeddable() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
24 private and internal fields
| Member | What it is |
|---|---|
private float breakForce | Serialized force (10000). Not read in this build. |
private bool btnClearGizmos | Inspector button that runs ClearGizmos. |
private bool btnUnEmbed | Inspector button labelled "UnEmbed". |
private float distanceToCheckForWedge | Raycast length for finding the embed spot: tip distance times raycastDistanceMultiplier. |
private EmbeddableEvent embedded | Event invoked on embed. The Embedded event adds to it. |
private bool isAllowedToEmbed | Backing field for IsAllowedToEmbed. |
private PlayerController lastEmbeddedPlayer | The player the object is stuck in, watched so it can unembed when they leave. |
private static Logger logger | NLog logger for debug messages. |
private float maxEmbedAngle | Minimum alignment (a dot product set from an angle) needed between tip and surface to embed. |
private float minHitEffectivenessToWedge | Lowest hit effectiveness, after the surface multiplier, that embeds (0.3 by default). |
private float minSquaredWedgingVelocity | Lowest squared impact speed that can embed (10 by default). |
private Vector3 negativeTipOffset | Local offset from the tip back to the origin. |
private NetworkRigidbody networkRigidbody | The object's network rigidbody, turned off while embedded. |
private float nonEmbeddingHitDrag | Velocity multiplier applied when a hit is at the wrong angle to embed (0.5 by default). |
private IEnumerable<Collider> othersColliders | Colliders of the struck entity whose collisions are ignored while embedded. |
private float raycastDistanceMultiplier | Scales the tip distance to get the wedge raycast length (1.5 by default). |
private static RaycastHit[] raycastHits | Shared buffer for the wedge raycast hits. |
private Rigidbody rigidbody | The object's Rigidbody. |
private MethodSyncClass<EmbedArguments> syncEmbed | Method sync made in Initialize for SyncEmbed, also sent to players on connect. |
private Transform tipPoint | Transform at the tip that goes in first. |
private EmbeddableEvent unembedded | Event invoked on unembed. The Unembedded event adds to it. |
private float wedgeMaximumPercentage | How deep a perfect hit sinks, as a share of the tip length (0.1 by default). |
private float wedgeMinimumPercentage | How deep the weakest embedding hit sinks, as a share of the tip length. |
private LayerMask wedgingLayers | Layers the wedge raycast hits. |
Properties
| Member | What it is |
|---|---|
IEnumerable<Collider> Colliders { get; } | The item's pickup colliders, or empty when the entity has no Pickup. Used to ignore collisions with what it is stuck in. |
NetworkEntity EmbeddedEntity { get; private set; } | The entity the item is stuck in, or null when stuck in the static world or not embedded. |
Rigidbody EmbeddedInto { get; private set; } | The rigidbody the item is stuck in, or null when stuck in the static world or not embedded. |
int EmbeddedRigidbodyIndex { get; private set; } | Index of the struck rigidbody in the target's EmbeddableManager list, or -1 when it has none or is not embedded. |
bool HasPickup { get; } | Whether the entity has a common Pickup. |
bool IsAllowedToEmbed { get; set; } | Turns embedding on or off for this item. Set it on the server. |
bool IsEmbedded { get; private set; } | Whether the item is currently stuck in something. |
1 private and internal property
Events
| Member | What it is |
|---|---|
event RefBoolDelegate CheckEmbed | Raised before an embed; set the ref bool to false to refuse it. Pickups add a handler that refuses while held or docked. |
event Action<Embeddable> Embedded | Raised on both sides when the item sticks into something. |
event Action<Embeddable> Unembedded | Raised on both sides when the item comes free. |
Methods
| Member | What it is |
|---|---|
void ExternalCollision(Collider collider, Vector3 hitPoint, Vector3 hitNormal) | Lets other code (such as EmbeddableRaycastProjectile) report a collision; embeds if angle, speed and surface allow it. |
override void Initialize() | Sets up the synced embed message (FixedJoint entity message type). |
override void OnConnected(Player player) | Server: sends the current embed state to a newly connected player. |
void UnEmbed() | Frees the item, unparents it and restores physics. Only syncs to clients when called on the server. |
32 private and internal methods
| Member | What it is |
|---|---|
private void Awake() | Works out the tip offsets, unembeds when the pickup is grabbed, blocks embedding while held or docked, and unembeds on destroy. |
private void ChildToStruckRigidbody(NetworkEntity otherEntity, Transform parent) | Makes the struck entity the chunking parent, saves as its child, and parents the transform to the struck body. |
private void ClearGizmos() | Empty. Run by the "Clear Gizmos" inspector button. |
private void DisableCollisionsWithOther(NetworkEntity other) | Finds the struck entity's colliders (player body, creature, pickup or collider group) and ignores collisions with them. |
private void Embed(Rigidbody struckRigidBody, Vector3 embedPosition, Quaternion embedRotation) | Server: sticks the object at a position, attaches it to the struck entity if any, fires Embedded and syncs to clients. |
private void EnforcePickupElibility(ref bool isValid) | Embed check that fails while the object's pickup is held or docked. |
private bool EnsureTipPoint() | Inspector fix: uses the object's own transform as the tip if none is set. |
private bool FindBestHit(int numberOfHits, RaycastHit[] raycastHits, out RaycastHit bestHit) | Picks the closest raycast hit that isn't the object itself or the throwing player's body. |
private float GetBestHitAngle(ContactPointStructure[] contacts) | Best dot product between the tip direction and the contact normals, used against maxEmbedAngle. |
private void GetBestHitLocation(float effectiveness, out Quaternion lastRotation, out Vector3 embedPosition) | Raycasts along the tip to find where to sit, sunk in deeper the more effective the hit was. |
private EmbedArguments GetSyncArgs() | Builds the embed sync data: state, position (local if in a body), rotation, struck entity, body index and scale. |
private void HandleDestroyed(NetworkEntity entity, bool isUnload) | Unembeds when the entity is destroyed, but not when it's only unloading. |
private void HandleEmbedInGlobalSpace(Vector3 embedPosition, Quaternion embedRotation) | Makes the body kinematic and places it at a world position and rotation. |
private void HandleEmbedInLocalSpace(Vector3 localPosition, Quaternion localRotation, Transform parent) | Makes the body kinematic and parents it at a local position and rotation. |
private void HandleStruckCollider(float hitEffectiveness, Collider struckCollider, ContactPointStructure[] contactPointStructures, Vector3 relativeVelocity) | Embeds if allowed, fast enough, and the surface and pickup checks pass. |
private void HandleStruckRigidbodyWithCorrectAngleAndVelocity(float hitEffectiveness, Collider struckCollider, Rigidbody struckRigidBody, float embeddMultiplier) | Embeds when hit effectiveness times the surface multiplier reaches minHitEffectivenessToWedge. |
private void HandleUnEmbedOnClient() | Client: makes the body physical again, moves it to the spawn folder and turns collisions back on. |
private void IgnoreCollisions(bool isIgnoring) | Turns collisions between this object's colliders and the struck entity's colliders off or on. |
private static bool IsRaycastedRigidbodyFromTheThrowingPlayer(PlayerCharacter playerCharacter, RaycastHit raycastHit) | True when a raycast hit is one of the throwing player's own body rigidbodies. |
private bool IsValidEmbed() | False if already embedded, embedding is off, or a CheckEmbed handler says no. |
private bool IsValidPickup(Collider struckCollider) | When the global settings restrict it, only lets the object stick into pickups with the allowed tag. |
private bool IsValidSurface(Collider struckCollider, ContactPointStructure[] contactPointStructures, ref float embedMultiplier) | Checks the surface's embed multiplier and, if it needs alignment, the hit angle. A bad angle slows the object. |
private void Alta.Impact.IToolHitDependant.OnCollided(Collision collision, bool isHitting, ImpactTool tool) | Server: on a plain collision (not a tool hit), tries to embed with full effectiveness. |
private void OnDrawGizmosSelected() | Editor: draws the wedge depth range and the raycast line. |
private void Alta.Impact.IToolHitDependant.OnHit(ImpactHitWithTool hit, ImpactTool tool) | Server: on a tool hit, tries to embed using the hit's effectiveness. |
private void ReenableCollisions() | Turns collisions with the struck entity back on, unless that player is now holding this object. |
private void SetupTipOffsets() | Stores the tip offset and the wedge raycast distance from the tip point. |
private void SyncEmbed(IPlayer player, Stream stream, EmbedArguments args) | Method sync for embed state. Clients embed or unembed to match and fire the events. |
private bool TryGetStruckObject(Rigidbody struckRigidBody, out NetworkEntity struckEntity, out int rigidbodyIndex, out EmbeddableManager manager) | Finds the struck network entity and, through an EmbeddableManager, the index of the body hit. |
private void UnChild() | Unparents the object, restores its save mode and chunk, and turns collisions back on. |
private void UnEmbedOnInteract(Interactable arg1, Interactor arg2) | Unembeds when someone grabs the object. |
private void UnEmbedOnPlayerLeave(PlayerController player) | Unembeds when the player the object is stuck in is about to leave. |
Used in
Members of other types that take, return or hold a Embeddable:
EmbeddableManager.allEmbedded, EmbeddableManager.AllEmbedded, EmbeddableManager.DeregisterEmbeddable, EmbeddableManager.EmbeddableAdded, EmbeddableManager.EmbeddableRemoved, EmbeddableManager.HandleEmbed, EmbeddableManager.HandleEmbeddableUnEmbed, EmbeddableManager.HandleUnEmbed, EmbeddableManager.RegisterEmbeddable, Arrow.embeddable, Arrow.StopArrowFlight, EmbeddableRaycastProjectile.embeddable.