Keep a dragged rigidbody on the mouse while the game plays
Dragging a sprite with a dynamic rigidbody in the scene view during play barely moved it. Only a quick drag and release got through. A dragged object should follow the mouse as if it had no rigidbody and start from rest when it is let go. - The scene view reports the dragged objects as held through EditorState. The game tick no longer writes its own position over a drag position that has not been read in yet. This affected every object in play, not only rigidbodies. - A held dynamic body turns kinematic and is set straight to the drag target. Gravity and velocity no longer pull it away between two mouse moves, and the "moved directly" warning stays quiet. - A body counts as held when the object itself, an object above it or its rigidbody is dragged. - On release the body turns dynamic again with linear and angular velocity set to 0. Not changed: a press on an unselected crate still lands on its same-sized collider (rule from #203). Dragging while play is paused and in the editor run is untouched. Tests: - ./check.sh: 155 files, 2273 tests, CHECK EXIT 0 (before 2271). - e2e 41 alone: 21 checks. e2e 1-16,39-43: 641 checks, all passed. - 2 unit tests: a held body stays where the drag puts it and starts from rest, also for a grip shorter than one physics step. The tick does not overwrite a drag position that is not read in yet. - 1 e2e check in 41b: the crate is lifted 150 units with the real mouse, holds exactly at -3490 for a second, then falls from rest (1.3 px, then 5.1 px) with an empty log. - Counter-checks: without holding in physics the crate falls back to the ground and the old warning shows. With the tick writing back the unit test fails. Without zeroing, a short grip keeps 490 px/s and the test fails. - Check total 1356 + 1 = 1357, calculated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d444b27fae
commit
d257298bc7
8 files changed
+136
-4
No files matched your search
@@ -234,6 +234,7 @@ export class PlaySession {
|
||||
return;
|
||||
}
|
||||
const wasPaused = world.paused;
|
||||
world.held = this.state.heldObjectIds;
|
||||
world.tick(world.paused ? awake : step);
|
||||
this.input.endFrame();
|
||||
if (world.paused !== wasPaused) this.state.setNotice(this.playNotice(), 'quiet');
|
||||
|
||||
@@ -227,6 +227,8 @@ export class EditorState {
|
||||
tilemapPaint: TilemapPaint = { tool: 'select', tileId: '', layerId: '', focus: 'all' };
|
||||
/** The asset the last `pingAsset` pointed at. */
|
||||
pingedAssetId: string | null = null;
|
||||
/** Objects the scene view is dragging: a running game holds their bodies to the pointer. */
|
||||
heldObjectIds: ReadonlySet<string> = new Set();
|
||||
/** The real (saved) model and its undo stack while `project` is the play-mode copy. */
|
||||
private edit: { project: Project; commands: CommandStack } | null = null;
|
||||
|
||||
|
||||
@@ -240,6 +240,7 @@ export class SceneViewport extends FreeViewport {
|
||||
const dy = (local.y - this.dragging.pointer.y) / this.view.zoom;
|
||||
if (!this.dragging.moved && Math.hypot(dx, dy) < DRAG_THRESHOLD) return;
|
||||
this.dragging.moved = true;
|
||||
this.state.heldObjectIds = new Set(this.dragging.items.map((item) => item.objectId));
|
||||
const holder = this.holder();
|
||||
if (!holder) return;
|
||||
for (const item of this.dragging.items) {
|
||||
@@ -321,6 +322,7 @@ export class SceneViewport extends FreeViewport {
|
||||
}
|
||||
const drag = this.dragging;
|
||||
this.dragging = null;
|
||||
this.state.heldObjectIds = new Set();
|
||||
this.perFrame.cancel();
|
||||
if (drag && !drag.moved && drag.onClick)
|
||||
this.state.select(objectSelection(drag.holderId, [drag.onClick]));
|
||||
|
||||
Reference in new issue
Block a user