Skip to main content

DontGoThroughObjects

A class in Root.Township, the global namespace.

Anti-tunnelling component: each physics step it raycasts along the rigidbody's movement and pulls it back to the first solid hit.

Constructors​

MemberWhat it is
DontGoThroughObjects()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

MemberWhat it is
LayerMask layerMaskLayers the raycast checks.
bool sendTriggerMessageNot used by this code.
float skinWidthFraction of the minimum extent taken off when placing the body before a hit.
6 private and internal fields
MemberWhat it is
private float minimumExtentSmallest half-extent of the collider bounds.
private Collider myColliderCollider on the same object, found in Start.
private Rigidbody myRigidbodyThe rigidbody being guarded.
private float partialExtentHow far before the hit point the body is placed, the minimum extent reduced by skinWidth.
private Vector3 previousPositionRigidbody position at the end of the last physics step.
private float sqrMinimumExtentSquare of minimumExtent, the movement threshold before a raycast runs.

Methods​

2 private and internal methods
MemberWhat it is
private void FixedUpdate()If the body moved further than its smallest extent, raycasts the path and moves it back in front of any non-trigger hit.
private void Start()Caches the collider and works out the extents from its bounds.