| | | 1 | | //======================================================================= |
| | | 2 | | // SolidBody2D.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2026–present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using Chronicler; |
| | | 9 | | using FixedMathSharp; |
| | | 10 | | using Gravitas.Colliders; |
| | | 11 | | using Gravitas.CollisionHandling; |
| | | 12 | | using Gravitas.Queries; |
| | | 13 | | using SwiftCollections; |
| | | 14 | | using System.Runtime.CompilerServices; |
| | | 15 | | |
| | | 16 | | namespace Gravitas; |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Represents deterministic pure 2D body state owned by one world context. |
| | | 20 | | /// </summary> |
| | | 21 | | public sealed partial class SolidBody2D : IRecordable |
| | | 22 | | { |
| | | 23 | | private Vector2d _position; |
| | | 24 | | private Fixed64 _rotation; |
| | | 25 | | private Vector2d _linearVelocity; |
| | | 26 | | private Vector2d _linearAccelerationStore; |
| | | 27 | | private Vector2d _deltaAcceleration; |
| | | 28 | | private Fixed64 _linearSpeed; |
| | | 29 | | private Fixed64 _mass; |
| | | 30 | | private Vector2d _localCenterOfMassOffset; |
| | | 31 | | private bool _centerOfMassOffsetExplicit; |
| | | 32 | | private Fixed64 _momentOfInertia; |
| | | 33 | | private Fixed64 _inverseMomentOfInertia; |
| | | 34 | | private Fixed64 _angularVelocity; |
| | | 35 | | private Fixed64 _angularAccelerationStore; |
| | | 36 | | private Fixed64 _deltaAngularAcceleration; |
| | | 37 | | private Fixed64 _angularSpeed; |
| | | 38 | | private bool _isSleeping; |
| | | 39 | | private BodyMotionType _motionType; |
| | | 40 | | private int _sleepFrameCount; |
| | 4645 | 41 | | private bool _sleepEnabled = true; |
| | 4645 | 42 | | private int _sleepFrameThreshold = 16; |
| | 4645 | 43 | | private Fixed64 _sleepLinearSpeedThreshold = (Fixed64)0.001f; |
| | 4645 | 44 | | private Fixed64 _sleepAngularSpeedThreshold = (Fixed64)0.001f; |
| | | 45 | | private ContinuousCollisionMode _continuousCollisionMode = ContinuousCollisionMode.Inherit; |
| | 4645 | 46 | | private int _continuousCollisionFrameToken = int.MinValue; |
| | 4645 | 47 | | private readonly SwiftList<ContinuousCollisionMotionSegment2D> _continuousCollisionTrajectory = |
| | 4645 | 48 | | new(PhysicsSettings.DefaultContinuousCollisionMaxToiIterations + 1); |
| | | 49 | | private bool _continuousCollisionHandoffPending; |
| | 4645 | 50 | | private int _continuousCollisionHandoffToken = int.MinValue; |
| | | 51 | | private Fixed64 _continuousCollisionHandoffRemainingTime; |
| | 4645 | 52 | | private readonly SwiftList<Physics2DHit> _continuousCollisionHits = new(); |
| | 4645 | 53 | | private readonly SwiftList<int> _rotationalContinuousCollisionCandidateIds = new(); |
| | 4645 | 54 | | private readonly SwiftList<PhysicsMixedHit> _continuousMixedCollisionHits = new(); |
| | | 55 | | |
| | | 56 | | /// <summary>Creates a pure 2D body bound to a host agent and collider.</summary> |
| | 4645 | 57 | | public SolidBody2D(IMatterAgent agent, LSCollider2D collider) |
| | | 58 | | { |
| | 4645 | 59 | | SwiftThrowHelper.ThrowIfNull(agent, nameof(agent)); |
| | 4645 | 60 | | SwiftThrowHelper.ThrowIfNull(collider, nameof(collider)); |
| | 4645 | 61 | | Agent = agent; |
| | 4645 | 62 | | Context = agent.Context; |
| | 4645 | 63 | | Collider = collider; |
| | 4645 | 64 | | } |
| | | 65 | | |
| | | 66 | | /// <summary>Gets the host agent that owns this body.</summary> |
| | | 67 | | public IMatterAgent Agent { get; } |
| | | 68 | | |
| | | 69 | | /// <summary>Gets the world context supplied by the host agent.</summary> |
| | | 70 | | public GravitasWorldContext Context { get; } |
| | | 71 | | |
| | | 72 | | /// <summary>Gets the runtime 2D collider attached to this body.</summary> |
| | | 73 | | public LSCollider2D Collider { get; } |
| | | 74 | | |
| | | 75 | | /// <summary> |
| | | 76 | | /// Gets the ephemeral simulated-body slot, or <c>-1</c> for a static or |
| | | 77 | | /// unregistered body. |
| | | 78 | | /// </summary> |
| | | 79 | | public int DynamicId { get; internal set; } = -1; |
| | | 80 | | |
| | | 81 | | /// <summary>Gets whether the body is initialized and registered.</summary> |
| | | 82 | | public bool Active { get; private set; } |
| | | 83 | | |
| | | 84 | | private BodyFreezeAxes2D _freezeAxes; |
| | | 85 | | |
| | | 86 | | /// <summary> |
| | | 87 | | /// Gets or sets the planar translational and yaw rotational degrees of |
| | | 88 | | /// freedom frozen for pure 2D solver response, integration, CCD, and |
| | | 89 | | /// rotational CCD. |
| | | 90 | | /// </summary> |
| | | 91 | | public BodyFreezeAxes2D FreezeAxes |
| | | 92 | | { |
| | | 93 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 106 | 94 | | get => _freezeAxes; |
| | | 95 | | set |
| | | 96 | | { |
| | 132 | 97 | | SwiftThrowHelper.ThrowIfArgument( |
| | 132 | 98 | | (value & ~BodyFreezeAxes2D.All) != BodyFreezeAxes2D.None, |
| | 132 | 99 | | nameof(value), |
| | 132 | 100 | | "Unsupported 2D freeze axis bits."); |
| | | 101 | | |
| | 132 | 102 | | if (_freezeAxes == value) |
| | 14 | 103 | | return; |
| | | 104 | | |
| | 118 | 105 | | _freezeAxes = value; |
| | 118 | 106 | | ApplyFreezeConstraintsToMotion(); |
| | 118 | 107 | | RefreshPartitionMobility(); |
| | 118 | 108 | | } |
| | | 109 | | } |
| | | 110 | | |
| | | 111 | | /// <summary> |
| | | 112 | | /// Gets whether both planar translation axes are frozen. |
| | | 113 | | /// </summary> |
| | | 114 | | public bool IsPositionFullyFrozen |
| | | 115 | | { |
| | | 116 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 99500 | 117 | | get => (_freezeAxes & BodyFreezeAxes2D.Position) == BodyFreezeAxes2D.Position; |
| | | 118 | | } |
| | | 119 | | |
| | | 120 | | /// <summary> |
| | | 121 | | /// Gets this body's explicit solver-controlled, host-controlled, or static |
| | | 122 | | /// runtime role. |
| | | 123 | | /// </summary> |
| | 271 | 124 | | public BodyMotionType MotionType => _motionType; |
| | | 125 | | |
| | | 126 | | /// <summary> |
| | | 127 | | /// Gets whether the solver controls this body. |
| | | 128 | | /// </summary> |
| | 109513 | 129 | | public bool IsDynamic => _motionType == BodyMotionType.Dynamic; |
| | | 130 | | |
| | | 131 | | /// <summary> |
| | | 132 | | /// Gets whether this body is excluded from per-frame motion. |
| | | 133 | | /// </summary> |
| | 13086 | 134 | | public bool IsStatic => _motionType == BodyMotionType.Static; |
| | | 135 | | |
| | | 136 | | /// <summary> |
| | | 137 | | /// Gets whether the host controls this body's pose. |
| | | 138 | | /// </summary> |
| | 31908 | 139 | | public bool IsKinematic => _motionType == BodyMotionType.Kinematic; |
| | | 140 | | |
| | | 141 | | /// <summary> |
| | | 142 | | /// Changes this registered body's runtime role between fixed-step |
| | | 143 | | /// transactions. |
| | | 144 | | /// </summary> |
| | | 145 | | /// <remarks> |
| | | 146 | | /// The transition preserves body, collider, pair, joint, and host identity, |
| | | 147 | | /// but clears incompatible motion, sleep, CCD, and solver-cache state before |
| | | 148 | | /// repartitioning. Freeze axes remain independent of the selected role. |
| | | 149 | | /// </remarks> |
| | | 150 | | /// <exception cref="System.ArgumentOutOfRangeException"> |
| | | 151 | | /// <paramref name="motionType"/> is undefined. |
| | | 152 | | /// </exception> |
| | | 153 | | /// <exception cref="System.InvalidOperationException"> |
| | | 154 | | /// The body is not currently registered, its context registration has been |
| | | 155 | | /// reset, or a simulation transaction or callback is active. |
| | | 156 | | /// </exception> |
| | | 157 | | public void SetMotionType(BodyMotionType motionType) |
| | | 158 | | { |
| | 60 | 159 | | if (!PrepareMotionTypeTransition(motionType)) |
| | 3 | 160 | | return; |
| | | 161 | | |
| | 49 | 162 | | CommitMotionTypeTransition(motionType); |
| | 49 | 163 | | } |
| | | 164 | | |
| | | 165 | | internal bool PrepareMotionTypeTransition(BodyMotionType motionType) |
| | | 166 | | { |
| | 131 | 167 | | motionType.ThrowIfInvalid(nameof(motionType)); |
| | 130 | 168 | | ThrowIfRuntimeRegistrationMissing(); |
| | 126 | 169 | | if (_motionType == motionType) |
| | 57 | 170 | | return false; |
| | | 171 | | |
| | 69 | 172 | | Context.ThrowIfFixedStepMutationNotAllowed(); |
| | 67 | 173 | | Collider.ValidateCurrentRuntimeTransform(); |
| | 65 | 174 | | if (motionType != BodyMotionType.Dynamic) |
| | 47 | 175 | | PublishAuthoritativePose(); |
| | | 176 | | |
| | 65 | 177 | | return true; |
| | | 178 | | } |
| | | 179 | | |
| | | 180 | | internal void CommitMotionTypeTransition(BodyMotionType motionType) |
| | | 181 | | { |
| | 64 | 182 | | ReconcileMotionTypeRegistration(motionType); |
| | | 183 | | |
| | 64 | 184 | | ClearMotionForMotionTypeTransition(); |
| | 64 | 185 | | _isSleeping = false; |
| | 64 | 186 | | _sleepFrameCount = 0; |
| | 64 | 187 | | InvalidateContinuousCollisionFrame(); |
| | 64 | 188 | | ApplyFreezeConstraintsToMotion(); |
| | 64 | 189 | | RefreshMassPropertiesFromColliderShape(); |
| | 64 | 190 | | RefreshPartitionMobility(); |
| | 64 | 191 | | } |
| | | 192 | | |
| | | 193 | | internal void ApplyLoadedMotionType(BodyMotionType motionType) |
| | | 194 | | { |
| | 56 | 195 | | motionType.ThrowIfInvalid(nameof(motionType)); |
| | 56 | 196 | | if (_motionType == motionType) |
| | 38 | 197 | | return; |
| | | 198 | | |
| | 18 | 199 | | if (!Active) |
| | | 200 | | { |
| | 4 | 201 | | _motionType = motionType; |
| | 4 | 202 | | return; |
| | | 203 | | } |
| | | 204 | | |
| | 14 | 205 | | ReconcileMotionTypeRegistration(motionType); |
| | 14 | 206 | | InvalidateContinuousCollisionFrame(); |
| | 14 | 207 | | } |
| | | 208 | | |
| | | 209 | | internal void PreflightLoadedMotionType(BodyMotionType motionType) |
| | | 210 | | { |
| | 60 | 211 | | motionType.ThrowIfInvalid(nameof(motionType)); |
| | 59 | 212 | | if (!Active) |
| | 6 | 213 | | return; |
| | | 214 | | |
| | 53 | 215 | | ThrowIfRuntimeRegistrationMissing(); |
| | 51 | 216 | | Context.ThrowIfFixedStepMutationNotAllowed(); |
| | 51 | 217 | | Collider.ValidateCurrentRuntimeTransform(); |
| | 51 | 218 | | } |
| | | 219 | | |
| | | 220 | | private void ThrowIfRuntimeRegistrationMissing() |
| | | 221 | | { |
| | 198 | 222 | | SwiftThrowHelper.ThrowIfTrue( |
| | 198 | 223 | | !Active, |
| | 198 | 224 | | nameof(SolidBody2D), |
| | 198 | 225 | | "2D body runtime state cannot change before initialization or after deactivation."); |
| | 196 | 226 | | SwiftThrowHelper.ThrowIfTrue( |
| | 196 | 227 | | !Context.Physics2D.TryGetColliderById(Collider.Id, out LSCollider2D? registeredCollider) |
| | 196 | 228 | | || !ReferenceEquals(registeredCollider, Collider), |
| | 196 | 229 | | nameof(SolidBody2D), |
| | 196 | 230 | | "2D body runtime state cannot change after its registration has been reset or replaced."); |
| | 191 | 231 | | } |
| | | 232 | | |
| | | 233 | | private void ReconcileMotionTypeRegistration(BodyMotionType motionType) |
| | | 234 | | { |
| | 78 | 235 | | BodyMotionType previousMotionType = _motionType; |
| | 78 | 236 | | Context.Physics2D.ClearWarmStartCachesForCollider(Collider); |
| | 78 | 237 | | Context.Constraints2D.ClearSolverCachesForBody(this); |
| | 78 | 238 | | Context.Physics2D.InvalidateContinuousCollisionStateForMotionTypeChange(this, DynamicId); |
| | | 239 | | |
| | 78 | 240 | | _motionType = motionType; |
| | 78 | 241 | | Context.Physics2D.RefreshBodyMotionTypeRegistration(this, previousMotionType); |
| | 78 | 242 | | Context.Physics2D.RefreshColliderServiceRefreshRegistration(Collider); |
| | 78 | 243 | | } |
| | | 244 | | |
| | | 245 | | private void ClearMotionForMotionTypeTransition() |
| | | 246 | | { |
| | 64 | 247 | | _linearVelocity = Vector2d.Zero; |
| | 64 | 248 | | _linearAccelerationStore = Vector2d.Zero; |
| | 64 | 249 | | _deltaAcceleration = Vector2d.Zero; |
| | 64 | 250 | | _linearSpeed = Fixed64.Zero; |
| | 64 | 251 | | _angularVelocity = Fixed64.Zero; |
| | 64 | 252 | | _angularAccelerationStore = Fixed64.Zero; |
| | 64 | 253 | | _deltaAngularAcceleration = Fixed64.Zero; |
| | 64 | 254 | | _angularSpeed = Fixed64.Zero; |
| | 64 | 255 | | } |
| | | 256 | | |
| | | 257 | | /// <summary> |
| | | 258 | | /// Selects the deterministic tunneling guard used when this pure 2D body commits frame movement. |
| | | 259 | | /// </summary> |
| | | 260 | | /// <exception cref="System.ArgumentOutOfRangeException">The value is not a declared continuous-collision mode.</exc |
| | | 261 | | public ContinuousCollisionMode ContinuousCollisionMode |
| | | 262 | | { |
| | | 263 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 108 | 264 | | get => _continuousCollisionMode; |
| | | 265 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 266 | | set |
| | | 267 | | { |
| | 388 | 268 | | value.ThrowIfInvalid(nameof(value)); |
| | 384 | 269 | | _continuousCollisionMode = value; |
| | 384 | 270 | | } |
| | | 271 | | } |
| | | 272 | | |
| | | 273 | | /// <summary> |
| | | 274 | | /// Gets the number of continuous-collision impacts consumed by the most recent 2D late simulation step. |
| | | 275 | | /// </summary> |
| | | 276 | | public int LastContinuousCollisionToiIterationCount { get; private set; } |
| | | 277 | | |
| | | 278 | | /// <summary> |
| | | 279 | | /// Gets whether the most recent 2D late simulation step reached the configured continuous-collision TOI iteration l |
| | | 280 | | /// </summary> |
| | | 281 | | public bool LastContinuousCollisionToiIterationLimitReached { get; private set; } |
| | | 282 | | |
| | | 283 | | /// <summary> |
| | | 284 | | /// Gets whether pure 2D yaw rotation is frozen. |
| | | 285 | | /// </summary> |
| | | 286 | | public bool IsRotationFullyFrozen |
| | | 287 | | { |
| | | 288 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 22465 | 289 | | get => (_freezeAxes & BodyFreezeAxes2D.Rotation) == BodyFreezeAxes2D.Rotation; |
| | | 290 | | } |
| | | 291 | | |
| | | 292 | | /// <summary>Gets or sets the body mass used to derive solver mass properties.</summary> |
| | | 293 | | public Fixed64 Mass |
| | | 294 | | { |
| | | 295 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 104 | 296 | | get => _mass; |
| | | 297 | | set |
| | | 298 | | { |
| | 4701 | 299 | | if (_mass == value) |
| | 47 | 300 | | return; |
| | | 301 | | |
| | 4654 | 302 | | _mass = value; |
| | 4654 | 303 | | RefreshMassPropertiesFromColliderShape(); |
| | 4654 | 304 | | } |
| | | 305 | | } |
| | | 306 | | |
| | | 307 | | /// <summary>Gets the reciprocal mass, or zero when the mass is non-positive.</summary> |
| | 94374 | 308 | | public Fixed64 InverseMass => _mass > Fixed64.Zero ? Fixed64.One / _mass : Fixed64.Zero; |
| | | 309 | | |
| | | 310 | | /// <summary> |
| | | 311 | | /// Gets whether solver-side response may translate this pure 2D body. |
| | | 312 | | /// </summary> |
| | 92311 | 313 | | public bool CanTranslate => Active && DynamicId >= 0 && IsDynamic && !IsPositionFullyFrozen && InverseMass > Fixed64 |
| | | 314 | | |
| | | 315 | | /// <summary> |
| | | 316 | | /// Gets whether solver-side response may rotate this pure 2D body around its yaw axis. |
| | | 317 | | /// </summary> |
| | 28132 | 318 | | public bool CanRotate => Active |
| | 28132 | 319 | | && DynamicId >= 0 |
| | 28132 | 320 | | && IsDynamic |
| | 28132 | 321 | | && !IsRotationFullyFrozen |
| | 28132 | 322 | | && _inverseMomentOfInertia > Fixed64.Zero; |
| | | 323 | | |
| | 59205 | 324 | | internal bool HasSolverMobility => CanTranslate || CanRotate; |
| | | 325 | | |
| | | 326 | | /// <summary> |
| | | 327 | | /// Gets the inverse mass that should be used by pure 2D and mixed response. |
| | | 328 | | /// </summary> |
| | 3901 | 329 | | public Fixed64 EffectiveInverseMass => CanTranslate ? InverseMass : Fixed64.Zero; |
| | | 330 | | |
| | | 331 | | /// <summary> |
| | | 332 | | /// Gets the inverse scalar moment that should be used by pure 2D angular response. |
| | | 333 | | /// </summary> |
| | 14096 | 334 | | public Fixed64 EffectiveInverseMomentOfInertia => CanRotate ? _inverseMomentOfInertia : Fixed64.Zero; |
| | | 335 | | |
| | | 336 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 337 | | internal Vector2d ProjectLinearMotion(Vector2d value) |
| | | 338 | | { |
| | 29312 | 339 | | if (value == Vector2d.Zero || IsPositionFullyFrozen) |
| | 14597 | 340 | | return Vector2d.Zero; |
| | | 341 | | |
| | 14715 | 342 | | Fixed64 x = (_freezeAxes & BodyFreezeAxes2D.PositionX) == BodyFreezeAxes2D.PositionX ? Fixed64.Zero : value.X; |
| | 14715 | 343 | | Fixed64 y = (_freezeAxes & BodyFreezeAxes2D.PositionY) == BodyFreezeAxes2D.PositionY ? Fixed64.Zero : value.Y; |
| | 14715 | 344 | | return new Vector2d(x, y); |
| | | 345 | | } |
| | | 346 | | |
| | | 347 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 348 | | private Vector2d ProjectLinearEndpoint(Vector2d start, Vector2d end) |
| | | 349 | | { |
| | 2238 | 350 | | Fixed64 x = (_freezeAxes & BodyFreezeAxes2D.PositionX) == BodyFreezeAxes2D.PositionX ? start.X : end.X; |
| | 2238 | 351 | | Fixed64 y = (_freezeAxes & BodyFreezeAxes2D.PositionY) == BodyFreezeAxes2D.PositionY ? start.Y : end.Y; |
| | 2238 | 352 | | return new Vector2d(x, y); |
| | | 353 | | } |
| | | 354 | | |
| | | 355 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 356 | | internal Fixed64 GetConstrainedInverseMass(Vector2d axis) |
| | | 357 | | { |
| | 10379 | 358 | | if (!CanTranslate || axis == Vector2d.Zero) |
| | 1991 | 359 | | return Fixed64.Zero; |
| | | 360 | | |
| | 8388 | 361 | | Fixed64 axisMagnitudeSquared = axis.MagnitudeSquared; |
| | 8388 | 362 | | if (axisMagnitudeSquared <= Fixed64.Epsilon) |
| | 2 | 363 | | return Fixed64.Zero; |
| | | 364 | | |
| | 8386 | 365 | | Vector2d allowedAxis = ProjectLinearMotion(axis); |
| | 8386 | 366 | | Fixed64 allowedScale = Vector2d.Dot(allowedAxis, axis) / axisMagnitudeSquared; |
| | 8386 | 367 | | return allowedScale > Fixed64.Zero ? InverseMass * allowedScale : Fixed64.Zero; |
| | | 368 | | } |
| | | 369 | | |
| | | 370 | | /// <summary>Gets the scalar moment of inertia around the yaw axis.</summary> |
| | 10 | 371 | | public Fixed64 MomentOfInertia => _momentOfInertia; |
| | | 372 | | |
| | | 373 | | /// <summary>Gets the reciprocal yaw moment of inertia.</summary> |
| | 7 | 374 | | public Fixed64 InverseMomentOfInertia => _inverseMomentOfInertia; |
| | | 375 | | |
| | | 376 | | /// <summary>Gets the signed yaw velocity.</summary> |
| | 13103 | 377 | | public Fixed64 AngularVelocity => _angularVelocity; |
| | | 378 | | |
| | | 379 | | /// <summary>Gets the accumulated yaw acceleration.</summary> |
| | 8 | 380 | | public Fixed64 AngularAcceleration => _angularAccelerationStore; |
| | | 381 | | |
| | | 382 | | /// <summary>Gets the absolute yaw speed.</summary> |
| | 16 | 383 | | public Fixed64 AngularSpeed => _angularSpeed; |
| | | 384 | | |
| | | 385 | | /// <summary>Gets the authoritative planar X/Z position.</summary> |
| | | 386 | | public Vector2d Position |
| | | 387 | | { |
| | | 388 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 24673 | 389 | | get => _position; |
| | | 390 | | } |
| | | 391 | | |
| | | 392 | | /// <summary>Gets the authoritative yaw rotation.</summary> |
| | | 393 | | public Fixed64 Rotation |
| | | 394 | | { |
| | | 395 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 23785 | 396 | | get => _rotation; |
| | | 397 | | } |
| | | 398 | | |
| | | 399 | | /// <summary>Gets the authoritative planar linear velocity.</summary> |
| | 12476 | 400 | | public Vector2d LinearVelocity => _linearVelocity; |
| | | 401 | | |
| | | 402 | | /// <summary>Gets the magnitude of <see cref="LinearVelocity"/>.</summary> |
| | 639 | 403 | | public Fixed64 LinearSpeed => _linearSpeed; |
| | | 404 | | |
| | | 405 | | /// <summary>Gets or sets the planar gravity acceleration applied to this body.</summary> |
| | | 406 | | public Vector2d Gravity { get; set; } = Vector2d.Zero; |
| | | 407 | | |
| | 4645 | 408 | | private Fixed64 _gravityScale = Fixed64.One; |
| | | 409 | | |
| | | 410 | | /// <summary> |
| | | 411 | | /// Multiplies this body's planar gravity vector. Zero disables body-authored gravity acceleration. |
| | | 412 | | /// </summary> |
| | | 413 | | public Fixed64 GravityScale |
| | | 414 | | { |
| | | 415 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 104 | 416 | | get => _gravityScale; |
| | | 417 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 418 | | set |
| | | 419 | | { |
| | 60 | 420 | | SwiftThrowHelper.ThrowIfArgument( |
| | 60 | 421 | | value < Fixed64.Zero, |
| | 60 | 422 | | nameof(value), |
| | 60 | 423 | | "2D gravity scale cannot be negative."); |
| | 59 | 424 | | _gravityScale = value; |
| | 59 | 425 | | } |
| | | 426 | | } |
| | | 427 | | |
| | | 428 | | /// <summary> |
| | | 429 | | /// Enables deterministic sleep evaluation for this body. Disabling sleep wakes a sleeping body immediately. |
| | | 430 | | /// </summary> |
| | | 431 | | public bool SleepEnabled |
| | | 432 | | { |
| | 3165 | 433 | | get => _sleepEnabled; |
| | | 434 | | set |
| | | 435 | | { |
| | 64 | 436 | | if (_sleepEnabled == value) |
| | 53 | 437 | | return; |
| | | 438 | | |
| | 11 | 439 | | _sleepEnabled = value; |
| | 11 | 440 | | if (!value) |
| | 10 | 441 | | Wake(); |
| | 11 | 442 | | } |
| | | 443 | | } |
| | | 444 | | |
| | | 445 | | /// <summary> |
| | | 446 | | /// Number of consecutive fixed frames below sleep thresholds required before the body sleeps. |
| | | 447 | | /// </summary> |
| | | 448 | | public int SleepFrameThreshold |
| | | 449 | | { |
| | 3746 | 450 | | get => _sleepFrameThreshold; |
| | | 451 | | set |
| | | 452 | | { |
| | 63 | 453 | | SwiftThrowHelper.ThrowIfNegative(value, nameof(value)); |
| | 62 | 454 | | _sleepFrameThreshold = value; |
| | 62 | 455 | | } |
| | | 456 | | } |
| | | 457 | | |
| | | 458 | | /// <summary> |
| | | 459 | | /// Linear speed at or below which the body can count toward sleeping. |
| | | 460 | | /// </summary> |
| | | 461 | | public Fixed64 SleepLinearSpeedThreshold |
| | | 462 | | { |
| | 2787 | 463 | | get => _sleepLinearSpeedThreshold; |
| | | 464 | | set |
| | | 465 | | { |
| | 59 | 466 | | SwiftThrowHelper.ThrowIfArgument( |
| | 59 | 467 | | value < Fixed64.Zero, |
| | 59 | 468 | | nameof(value), |
| | 59 | 469 | | "2D sleep linear speed threshold cannot be negative."); |
| | 58 | 470 | | _sleepLinearSpeedThreshold = value; |
| | 58 | 471 | | } |
| | | 472 | | } |
| | | 473 | | |
| | | 474 | | /// <summary> |
| | | 475 | | /// Angular speed at or below which the body can count toward sleeping. |
| | | 476 | | /// </summary> |
| | | 477 | | public Fixed64 SleepAngularSpeedThreshold |
| | | 478 | | { |
| | | 479 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 108 | 480 | | get => _sleepAngularSpeedThreshold; |
| | | 481 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 482 | | set |
| | | 483 | | { |
| | 61 | 484 | | SwiftThrowHelper.ThrowIfArgument( |
| | 61 | 485 | | value < Fixed64.Zero, |
| | 61 | 486 | | nameof(value), |
| | 61 | 487 | | "2D angular sleep threshold cannot be negative."); |
| | 61 | 488 | | _sleepAngularSpeedThreshold = value; |
| | 61 | 489 | | } |
| | | 490 | | } |
| | | 491 | | |
| | | 492 | | /// <summary>Gets whether the body is sleeping.</summary> |
| | 49066 | 493 | | public bool IsSleeping => _isSleeping; |
| | | 494 | | |
| | 48447 | 495 | | internal bool IsAwakeForCollision => HasSolverMobility && !IsSleeping; |
| | | 496 | | |
| | | 497 | | /// <summary>Initializes and registers the body at an authoritative planar pose.</summary> |
| | | 498 | | public void Initialize( |
| | | 499 | | Vector2d position, |
| | | 500 | | Fixed64 rotation = default, |
| | | 501 | | BodyMotionType motionType = BodyMotionType.Dynamic) |
| | | 502 | | { |
| | 4660 | 503 | | motionType.ThrowIfInvalid(nameof(motionType)); |
| | 4660 | 504 | | SwiftThrowHelper.ThrowIfTrue(Active, nameof(SolidBody2D), "2D body is already initialized."); |
| | 4660 | 505 | | SwiftThrowHelper.ThrowIfArgument( |
| | 4660 | 506 | | Collider.Id >= 0 |
| | 4660 | 507 | | || (Collider.HasHostBinding && !ReferenceEquals(Collider.Body, this)), |
| | 4660 | 508 | | nameof(Collider), |
| | 4660 | 509 | | "Body collider must be unregistered and free of another host binding before initialization."); |
| | 4658 | 510 | | Fixed64 canonicalRotation = CanonicalizeRotation(rotation); |
| | 4658 | 511 | | Collider.PreflightBodyInitialization(this, position, canonicalRotation); |
| | | 512 | | |
| | 4652 | 513 | | _position = position; |
| | 4652 | 514 | | _rotation = canonicalRotation; |
| | 4652 | 515 | | _linearVelocity = Vector2d.Zero; |
| | 4652 | 516 | | _linearAccelerationStore = Vector2d.Zero; |
| | 4652 | 517 | | _deltaAcceleration = Vector2d.Zero; |
| | 4652 | 518 | | _linearSpeed = Fixed64.Zero; |
| | 4652 | 519 | | _angularVelocity = Fixed64.Zero; |
| | 4652 | 520 | | _angularAccelerationStore = Fixed64.Zero; |
| | 4652 | 521 | | _deltaAngularAcceleration = Fixed64.Zero; |
| | 4652 | 522 | | _angularSpeed = Fixed64.Zero; |
| | 4652 | 523 | | _isSleeping = false; |
| | 4652 | 524 | | _motionType = motionType; |
| | 4652 | 525 | | _sleepFrameCount = 0; |
| | 4652 | 526 | | InvalidateContinuousCollisionFrame(); |
| | 4652 | 527 | | ResetGroundingForInitialize(position); |
| | 4652 | 528 | | Active = true; |
| | 4652 | 529 | | Collider.Initialize(this); |
| | 4652 | 530 | | RefreshMassPropertiesFromColliderShape(); |
| | 4652 | 531 | | Context.Physics2D.AssimilateBody(this, motionType); |
| | 4652 | 532 | | CheckGroundForSimulation(); |
| | 4652 | 533 | | } |
| | | 534 | | |
| | | 535 | | /// <summary> |
| | | 536 | | /// Gets a world-space point from the authoritative 2D body pose and committed collider scale. |
| | | 537 | | /// </summary> |
| | | 538 | | public Vector2d GetWorldPoint(Vector2d point) |
| | | 539 | | { |
| | 4 | 540 | | bool transformed = TryGetWorldPoint(point, out Vector2d result); |
| | 4 | 541 | | SwiftThrowHelper.ThrowIfTrue( |
| | 4 | 542 | | !transformed, |
| | 4 | 543 | | nameof(Collider), |
| | 4 | 544 | | "Cannot get the world point because the 2D collider has no committed scale or the final coordinate is not re |
| | 3 | 545 | | return result; |
| | | 546 | | } |
| | | 547 | | |
| | | 548 | | /// <summary> |
| | | 549 | | /// Attempts to get a world-space point from the authoritative 2D body pose and committed collider scale. |
| | | 550 | | /// </summary> |
| | | 551 | | public bool TryGetWorldPoint(Vector2d point, out Vector2d result) |
| | | 552 | | { |
| | 215 | 553 | | if (!Collider.TryGetCommittedOwnerScale(out Vector2d scale)) |
| | | 554 | | { |
| | 2 | 555 | | result = Vector2d.Zero; |
| | 2 | 556 | | return false; |
| | | 557 | | } |
| | | 558 | | |
| | 213 | 559 | | return Vector2d.TryTransformScaledPoint( |
| | 213 | 560 | | Position, |
| | 213 | 561 | | point, |
| | 213 | 562 | | scale, |
| | 213 | 563 | | Rotation, |
| | 213 | 564 | | out result); |
| | | 565 | | } |
| | | 566 | | |
| | | 567 | | /// <summary> |
| | | 568 | | /// Gets a body-local point from the authoritative 2D body pose and committed collider scale. |
| | | 569 | | /// </summary> |
| | | 570 | | public Vector2d GetLocalPoint(Vector2d point) |
| | | 571 | | { |
| | 3 | 572 | | bool transformed = TryGetLocalPoint(point, out Vector2d result); |
| | 3 | 573 | | SwiftThrowHelper.ThrowIfTrue( |
| | 3 | 574 | | !transformed, |
| | 3 | 575 | | nameof(Collider), |
| | 3 | 576 | | "Cannot get the local point because the 2D collider has no committed scale, its scale is singular, or the fi |
| | 2 | 577 | | return result; |
| | | 578 | | } |
| | | 579 | | |
| | | 580 | | /// <summary> |
| | | 581 | | /// Attempts to get a body-local point from the authoritative 2D body pose and committed collider scale. |
| | | 582 | | /// </summary> |
| | | 583 | | public bool TryGetLocalPoint(Vector2d point, out Vector2d result) |
| | | 584 | | { |
| | 214 | 585 | | if (!Collider.TryGetCommittedOwnerScale(out Vector2d scale)) |
| | | 586 | | { |
| | 2 | 587 | | result = Vector2d.Zero; |
| | 2 | 588 | | return false; |
| | | 589 | | } |
| | | 590 | | |
| | 212 | 591 | | return Vector2d.TryInverseTransformScaledPoint( |
| | 212 | 592 | | Position, |
| | 212 | 593 | | point, |
| | 212 | 594 | | scale, |
| | 212 | 595 | | Rotation, |
| | 212 | 596 | | out result); |
| | | 597 | | } |
| | | 598 | | |
| | | 599 | | /// <summary> |
| | | 600 | | /// Resets authoritative 2D pose and clears accumulated linear/angular motion for deterministic fixture reuse. |
| | | 601 | | /// </summary> |
| | | 602 | | /// <param name="position">The new X/Z-plane position.</param> |
| | | 603 | | /// <param name="rotation">The new yaw rotation in radians.</param> |
| | | 604 | | public void ResetPosition(Vector2d position = default, Fixed64 rotation = default) |
| | | 605 | | { |
| | 92 | 606 | | PreflightStaticPoseChange(); |
| | 91 | 607 | | Fixed64 canonicalRotation = CanonicalizeRotation(rotation); |
| | 91 | 608 | | SwiftThrowHelper.ThrowIfTrue( |
| | 91 | 609 | | !Collider.TryPrepareBodyPose(position, canonicalRotation), |
| | 91 | 610 | | nameof(position), |
| | 91 | 611 | | "The requested 2D body pose produces collider geometry outside the representable coordinate domain."); |
| | 90 | 612 | | _linearVelocity = Vector2d.Zero; |
| | 90 | 613 | | _linearAccelerationStore = Vector2d.Zero; |
| | 90 | 614 | | _deltaAcceleration = Vector2d.Zero; |
| | 90 | 615 | | _linearSpeed = Fixed64.Zero; |
| | 90 | 616 | | _angularVelocity = Fixed64.Zero; |
| | 90 | 617 | | _angularAccelerationStore = Fixed64.Zero; |
| | 90 | 618 | | _deltaAngularAcceleration = Fixed64.Zero; |
| | 90 | 619 | | _angularSpeed = Fixed64.Zero; |
| | 90 | 620 | | bool wasSleeping = _isSleeping; |
| | 90 | 621 | | _isSleeping = false; |
| | 90 | 622 | | _sleepFrameCount = 0; |
| | 90 | 623 | | _position = position; |
| | 90 | 624 | | _rotation = canonicalRotation; |
| | 90 | 625 | | InvalidateContinuousCollisionFrame(); |
| | 90 | 626 | | ResetGroundingForInitialize(position); |
| | | 627 | | |
| | 90 | 628 | | if (!Active) |
| | 1 | 629 | | return; |
| | | 630 | | |
| | 89 | 631 | | Collider.PublishPreparedExplicitBodyPose(); |
| | 89 | 632 | | RefreshStaticColliderAfterExplicitPoseChange(); |
| | 89 | 633 | | if (wasSleeping) |
| | 1 | 634 | | Context.Collisions2D.RefreshPartitionAwakeState(Collider); |
| | 89 | 635 | | } |
| | | 636 | | |
| | | 637 | | /// <summary>Puts an eligible body to sleep and clears its motion.</summary> |
| | | 638 | | public void Sleep() |
| | | 639 | | { |
| | 211 | 640 | | if (!CanSleep) |
| | 2 | 641 | | return; |
| | | 642 | | |
| | 209 | 643 | | _isSleeping = true; |
| | 209 | 644 | | _sleepFrameCount = SleepFrameThreshold; |
| | 209 | 645 | | _linearVelocity = Vector2d.Zero; |
| | 209 | 646 | | _linearAccelerationStore = Vector2d.Zero; |
| | 209 | 647 | | _deltaAcceleration = Vector2d.Zero; |
| | 209 | 648 | | _linearSpeed = Fixed64.Zero; |
| | 209 | 649 | | _angularVelocity = Fixed64.Zero; |
| | 209 | 650 | | _angularAccelerationStore = Fixed64.Zero; |
| | 209 | 651 | | _deltaAngularAcceleration = Fixed64.Zero; |
| | 209 | 652 | | _angularSpeed = Fixed64.Zero; |
| | 209 | 653 | | Context.Collisions2D.RefreshPartitionAwakeState(Collider); |
| | 209 | 654 | | } |
| | | 655 | | |
| | | 656 | | /// <summary>Wakes the body and resumes collision participation.</summary> |
| | | 657 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 658 | | public void Wake() |
| | | 659 | | { |
| | 1174 | 660 | | bool wasSleeping = _isSleeping; |
| | 1174 | 661 | | _sleepFrameCount = 0; |
| | 1174 | 662 | | _isSleeping = false; |
| | 1174 | 663 | | if (Active && wasSleeping) |
| | 68 | 664 | | Context.Collisions2D.RefreshPartitionAwakeState(Collider); |
| | 1174 | 665 | | } |
| | | 666 | | |
| | | 667 | | internal void WakeFromCollision() |
| | | 668 | | { |
| | 2730 | 669 | | if (!_isSleeping) |
| | 2648 | 670 | | return; |
| | | 671 | | |
| | 82 | 672 | | _sleepFrameCount = 0; |
| | 82 | 673 | | _isSleeping = false; |
| | 82 | 674 | | Context.Collisions2D.RefreshPartitionAwakeState(Collider); |
| | 82 | 675 | | } |
| | | 676 | | |
| | 6 | 677 | | internal void LateSimulate() => LateSimulate(updateSleepState: true, updateColliderState: true); |
| | | 678 | | |
| | | 679 | | internal void LateSimulate(bool updateSleepState, bool updateColliderState) |
| | | 680 | | { |
| | 2327 | 681 | | if (!Active) |
| | 1 | 682 | | return; |
| | | 683 | | |
| | 2326 | 684 | | CaptureGroundedStepState(); |
| | | 685 | | try |
| | | 686 | | { |
| | 2326 | 687 | | LastContinuousCollisionToiIterationCount = 0; |
| | 2326 | 688 | | LastContinuousCollisionToiIterationLimitReached = false; |
| | | 689 | | |
| | 2326 | 690 | | if (TryConsumeContinuousCollisionHandoff(updateSleepState, updateColliderState)) |
| | 39 | 691 | | return; |
| | | 692 | | |
| | 2287 | 693 | | EnsureContinuousCollisionFramePrepared(Context.LateSimulateToken); |
| | | 694 | | |
| | 2287 | 695 | | if (IsKinematic) |
| | 166 | 696 | | UpdateKinematicPositionAndRotation(updateColliderState); |
| | | 697 | | |
| | 2287 | 698 | | if (!HasSolverMobility) |
| | | 699 | | { |
| | 171 | 700 | | _linearAccelerationStore = Vector2d.Zero; |
| | 171 | 701 | | _deltaAcceleration = Vector2d.Zero; |
| | 171 | 702 | | _angularAccelerationStore = Fixed64.Zero; |
| | 171 | 703 | | _deltaAngularAcceleration = Fixed64.Zero; |
| | 171 | 704 | | return; |
| | | 705 | | } |
| | | 706 | | |
| | 2116 | 707 | | if (_isSleeping) |
| | 65 | 708 | | return; |
| | | 709 | | |
| | 2051 | 710 | | Fixed64 startRotation = _rotation; |
| | 2051 | 711 | | Fixed64 proposedRotation = startRotation + _angularVelocity * Context.DeltaTime; |
| | | 712 | | |
| | 2051 | 713 | | Vector2d startPosition = _position; |
| | 2051 | 714 | | Vector2d proposedPosition = startPosition + _linearVelocity * Context.DeltaTime; |
| | 2051 | 715 | | if (ShouldUseRotationalContinuousCollisionArbiter( |
| | 2051 | 716 | | startPosition, |
| | 2051 | 717 | | proposedPosition, |
| | 2051 | 718 | | startRotation, |
| | 2051 | 719 | | proposedRotation, |
| | 2051 | 720 | | forceContinuous: false)) |
| | | 721 | | { |
| | 154 | 722 | | TryResolveRotationalContinuousCollision( |
| | 154 | 723 | | startPosition, |
| | 154 | 724 | | ref proposedPosition, |
| | 154 | 725 | | startRotation, |
| | 154 | 726 | | ref proposedRotation); |
| | | 727 | | } |
| | | 728 | | else |
| | | 729 | | { |
| | 1897 | 730 | | TryResolveContinuousCollision(startPosition, ref proposedPosition); |
| | | 731 | | } |
| | 2050 | 732 | | proposedPosition = ProjectLinearEndpoint(startPosition, proposedPosition); |
| | 2050 | 733 | | _position = proposedPosition; |
| | 2050 | 734 | | _rotation = CanonicalizeRotation(proposedRotation); |
| | 2050 | 735 | | if (updateColliderState) |
| | 10 | 736 | | Collider.Rebuild(); |
| | | 737 | | |
| | 2050 | 738 | | if (updateSleepState) |
| | 2 | 739 | | UpdateSleepState(); |
| | 2050 | 740 | | } |
| | | 741 | | finally |
| | | 742 | | { |
| | 2326 | 743 | | CompleteGroundedStepState(); |
| | 2326 | 744 | | } |
| | 2325 | 745 | | } |
| | | 746 | | |
| | | 747 | | internal void UpdateSleepStateAfterPhysicsStep() |
| | | 748 | | { |
| | 2268 | 749 | | if (!_isSleeping) |
| | 2224 | 750 | | UpdateSleepState(); |
| | 2268 | 751 | | } |
| | | 752 | | |
| | | 753 | | internal void OnVisualize() |
| | | 754 | | { |
| | 6 | 755 | | if (IsKinematic) |
| | 1 | 756 | | return; |
| | | 757 | | |
| | 5 | 758 | | SetHostWorldPose(Agent.Transform, _position, _rotation); |
| | 5 | 759 | | } |
| | | 760 | | |
| | | 761 | | private void UpdateKinematicPositionAndRotation(bool updateColliderState) |
| | | 762 | | { |
| | 166 | 763 | | Vector2d startPosition = _position; |
| | 166 | 764 | | Fixed64 startRotation = _rotation; |
| | 166 | 765 | | FixedTransform transform = Agent.Transform; |
| | 166 | 766 | | Vector2d requestedHostPosition = transform.WorldPositionXZ; |
| | 166 | 767 | | Fixed64 requestedHostRotation = CanonicalizeRotation( |
| | 166 | 768 | | transform.WorldRotationXZRadians); |
| | 166 | 769 | | Vector2d kinematicPosition = ContinuousCollisionFrameEnd; |
| | 166 | 770 | | Fixed64 kinematicRotation = ContinuousCollisionFrameTargetRotation; |
| | 166 | 771 | | if (startPosition == kinematicPosition && startRotation == kinematicRotation) |
| | | 772 | | { |
| | 6 | 773 | | SetHostWorldPose(transform, kinematicPosition, kinematicRotation); |
| | 6 | 774 | | return; |
| | | 775 | | } |
| | | 776 | | |
| | 160 | 777 | | Wake(); |
| | 160 | 778 | | Vector2d resolvedPosition = kinematicPosition; |
| | 160 | 779 | | Fixed64 resolvedRotation = kinematicRotation; |
| | 160 | 780 | | if (ShouldUseRotationalContinuousCollisionArbiter( |
| | 160 | 781 | | startPosition, |
| | 160 | 782 | | resolvedPosition, |
| | 160 | 783 | | startRotation, |
| | 160 | 784 | | resolvedRotation, |
| | 160 | 785 | | forceContinuous: false)) |
| | | 786 | | { |
| | 75 | 787 | | TryResolveKinematicRotationalContinuousCollision( |
| | 75 | 788 | | startPosition, |
| | 75 | 789 | | ref resolvedPosition, |
| | 75 | 790 | | startRotation, |
| | 75 | 791 | | ref resolvedRotation); |
| | | 792 | | } |
| | | 793 | | else |
| | | 794 | | { |
| | 85 | 795 | | TryResolveKinematicContinuousCollision(startPosition, ref resolvedPosition); |
| | | 796 | | } |
| | | 797 | | |
| | 160 | 798 | | resolvedRotation = CanonicalizeRotation(resolvedRotation); |
| | 160 | 799 | | if (resolvedPosition != requestedHostPosition |
| | 160 | 800 | | || resolvedRotation != requestedHostRotation) |
| | 52 | 801 | | SetHostWorldPose(transform, resolvedPosition, resolvedRotation); |
| | | 802 | | |
| | 160 | 803 | | _position = resolvedPosition; |
| | 160 | 804 | | _rotation = resolvedRotation; |
| | 160 | 805 | | if (updateColliderState) |
| | 3 | 806 | | Collider.Rebuild(); |
| | 160 | 807 | | } |
| | | 808 | | |
| | | 809 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 810 | | private static Fixed64 CanonicalizeRotation(Fixed64 rotation) => |
| | 13450 | 811 | | PlanarRotation.Canonicalize(rotation); |
| | | 812 | | |
| | | 813 | | private static void SetHostWorldPose( |
| | | 814 | | FixedTransform transform, |
| | | 815 | | Vector2d position, |
| | | 816 | | Fixed64 rotation) |
| | | 817 | | { |
| | 164 | 818 | | Vector3d currentWorldPosition = transform.WorldPosition; |
| | 164 | 819 | | Vector3d worldPosition = new(position.X, currentWorldPosition.Y, position.Y); |
| | 164 | 820 | | FixedQuaternion worldRotation = FixedQuaternion.FromAxisAngle(Vector3d.Up, -rotation); |
| | 164 | 821 | | SwiftThrowHelper.ThrowIfTrue( |
| | 164 | 822 | | !transform.TrySetWorldPose(worldPosition, worldRotation), |
| | 164 | 823 | | nameof(FixedTransform), |
| | 164 | 824 | | "Host transform cannot represent the requested world-space 2D pose."); |
| | 164 | 825 | | } |
| | | 826 | | |
| | | 827 | | private void PublishAuthoritativePose() => |
| | 47 | 828 | | SetHostWorldPose(Agent.Transform, _position, _rotation); |
| | | 829 | | |
| | | 830 | | /// <summary> |
| | | 831 | | /// Removes this body and its collider from the pure 2D runtime service. |
| | | 832 | | /// </summary> |
| | | 833 | | public void Deactivate() |
| | | 834 | | { |
| | 134 | 835 | | if (!ReferenceEquals(Collider.Body, this)) |
| | 11 | 836 | | return; |
| | | 837 | | |
| | 123 | 838 | | DiscardContinuousCollisionHandoff(); |
| | 123 | 839 | | InvalidateContinuousCollisionFrame(); |
| | 123 | 840 | | Context.Physics2D.DessimilateBody(this); |
| | 123 | 841 | | Active = false; |
| | 123 | 842 | | DynamicId = -1; |
| | 123 | 843 | | Collider.IsActive = false; |
| | 123 | 844 | | Collider.ClearPhysicsState(); |
| | 123 | 845 | | Collider.ClearBindingState(); |
| | 123 | 846 | | } |
| | | 847 | | } |