-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scale fluctuates when just grabbing a block on top of the scale with keyboard #414
Labels
Comments
I tried LockConstraint, but it had the same bug on the scale and very buggy collision behavior: Subject: [PATCH] comment
---
Index: js/common/model/PhysicsEngine.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/common/model/PhysicsEngine.ts b/js/common/model/PhysicsEngine.ts
--- a/js/common/model/PhysicsEngine.ts (revision 234443020a88a811a2c932ac0fb83d4d6ba2a85d)
+++ b/js/common/model/PhysicsEngine.ts (date 1727894936487)
@@ -53,7 +53,7 @@
private readonly world: p2.World;
// Maps {number} body.id => {p2.RevoluteConstraint}
- private readonly pointerConstraintMap: Record<number, p2.RevoluteConstraint>;
+ private readonly pointerConstraintMap: Record<number, p2.LockConstraint>;
// Maps {number} body.id => {p2.Body}. Contains bodies that are empty, and specifically used for
// pointer constraints (so they can be positioned to where the pointer is).
@@ -367,38 +367,42 @@
assert && assert( !this.pointerConstraintMap.hasOwnProperty( body.id ), 'there is already a pointer constraint for this body' );
assert && assert( !this.nullBodyMap.hasOwnProperty( body.id ), 'there is already a null body for this body' );
- // Create an empty body used for the constraint (we don't want it intersecting). It will just be used for applying
- // the effects of this constraint.
- const nullBody = new p2.Body();
+ // Create an empty body used for the constraint
+ const nullBody = new p2.Body( {
+ mass: 0, // Make sure the nullBody is static
+ position: [ position.x * SIZE_SCALE, position.y * SIZE_SCALE ]
+ } );
this.nullBodyMap[ body.id ] = nullBody;
- const globalPoint = PhysicsEngine.vectorToP2( position );
- const localPoint = p2.vec2.create();
- body.toLocalFrame( localPoint, globalPoint );
this.world.addBody( nullBody );
body.wakeUp();
- const pointerConstraint = new p2.RevoluteConstraint( nullBody, body, {
- localPivotA: globalPoint,
- localPivotB: localPoint,
- maxForce: DensityBuoyancyCommonQueryParameters.p2PointerMassForce * body.mass + DensityBuoyancyCommonQueryParameters.p2PointerBaseForce
+ const lockConstraint = new p2.LockConstraint( nullBody, body, {
+ collideConnected: false
+ // Optionally, you can add stiffness and damping if supported
} );
- this.pointerConstraintMap[ body.id ] = pointerConstraint;
- this.world.addConstraint( pointerConstraint );
+ this.pointerConstraintMap[ body.id ] = lockConstraint;
+ this.world.addConstraint( lockConstraint );
}
/**
* Updates a pointer constraint so that the body will essentially be dragged to the new position.
*/
public updatePointerConstraint( body: PhysicsEngineBody, position: Vector2 ): void {
- const pointerConstraint = this.pointerConstraintMap[ body.id ];
- assert && assert( pointerConstraint, `pointer constraint expected for physics body #${body.id}` );
+ const lockConstraint = this.pointerConstraintMap[ body.id ];
+ assert && assert( lockConstraint, `pointer constraint expected for physics body #${body.id}` );
+
+ const nullBody = this.nullBodyMap[ body.id ];
+ assert && assert( nullBody, `null body expected for physics body #${body.id}` );
- // @ts-expect-error it should have pivotA...
- p2.vec2.copy( pointerConstraint.pivotA, PhysicsEngine.vectorToP2( position ) );
- pointerConstraint.bodyA.wakeUp();
- pointerConstraint.bodyB.wakeUp();
+ // Update the position of the nullBody to the new pointer position
+ nullBody.position[ 0 ] = position.x * SIZE_SCALE;
+ nullBody.position[ 1 ] = position.y * SIZE_SCALE;
+
+ // Wake up both bodies to ensure the constraint is processed
+ body.wakeUp();
+ nullBody.wakeUp();
}
/**
@@ -407,9 +411,9 @@
public removePointerConstraint( body: PhysicsEngineBody ): void {
const nullBody = this.nullBodyMap[ body.id ];
assert && assert( nullBody, `cannot remove physics body #${body.id}` );
- const pointerConstraint = this.pointerConstraintMap[ body.id ];
+ const lockConstraint = this.pointerConstraintMap[ body.id ];
- this.world.removeConstraint( pointerConstraint );
+ this.world.removeConstraint( lockConstraint );
this.world.removeBody( nullBody );
delete this.nullBodyMap[ body.id ]; |
zepumph
added a commit
that referenced
this issue
Oct 2, 2024
zepumph
added a commit
that referenced
this issue
Oct 2, 2024
zepumph
added a commit
that referenced
this issue
Oct 2, 2024
zepumph
added a commit
that referenced
this issue
Oct 2, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Test device
Win 10 Desktop
Operating System
Win 10
Browser
Chrome 129.0.6668.59
Problem description
For phetsims/qa#1141 Scale weight either fluctuates rapidly or switches between two different weights just grabbing the block and no other inputs. I know there are other issues regarding the weight measurements on scales, apologies if this is already being addressed. This happens in both Buoyancy: basics and Buoyancy. It does not happen in Density.
Steps to reproduce
Visuals
Buoyancy_.Basics.-.mp4
The text was updated successfully, but these errors were encountered: