Skip to content

fix: auto-detach parented entities on applyImpulse (fixes SDK #32)#18

Open
cryptochris8 wants to merge 1 commit intohytopiagg:mainfrom
cryptochris8:fix/apply-impulse-after-set-parent
Open

fix: auto-detach parented entities on applyImpulse (fixes SDK #32)#18
cryptochris8 wants to merge 1 commit intohytopiagg:mainfrom
cryptochris8:fix/apply-impulse-after-set-parent

Conversation

@cryptochris8
Copy link
Copy Markdown

Summary

Fixes SDK issue #32applyImpulse() silently failing after setParent().

When an entity is parented, its rigid body type changes to KINEMATIC_VELOCITY to prevent independent physics. However, this causes applyImpulse() to silently fail since it requires a DYNAMIC body. This breaks the common "pick up and throw" game pattern.

Fix: Overrides applyImpulse, applyImpulseAtPoint, and applyTorqueImpulse in Entity.ts to automatically detach from the parent before applying the impulse. The entity's current world position and rotation are preserved during detachment so it doesn't snap to the origin. The body type is restored to DYNAMIC through the existing _lastParentlessType mechanism.

At default (no parent), behavior is completely unchanged — the override just delegates to super.

Test plan

  • Create entity, parent it to another entity, call applyImpulse() — entity should detach and fly
  • Verify the entity stays at its visual position after detaching (no teleport to origin)
  • Verify applyImpulseAtPoint() and applyTorqueImpulse() also work on parented entities
  • Verify unparented entities still receive impulses normally

🤖 Generated with Claude Code

…gg#32)

When applyImpulse, applyImpulseAtPoint, or applyTorqueImpulse is called
on a parented entity, automatically detach it from its parent while
preserving the current world position and rotation. This enables the
common "pick up and throw" pattern where entities are parented to a
player and then launched with an impulse.

Previously, parented entities had their rigid body type set to
KINEMATIC_VELOCITY, causing _requireDynamic() to silently reject
impulse calls. The fix detaches and restores the original body type
before applying the impulse.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant