mirror of
https://github.com/photonstorm/phaser
synced 2025-03-05 07:47:28 +00:00
Testing issue with sticky bodies
This commit is contained in:
parent
1518f49c23
commit
6a145049b1
3 changed files with 70 additions and 68 deletions
|
@ -6,13 +6,14 @@
|
|||
|
||||
var ArrayAdd = require('../../utils/array/Add');
|
||||
var CircleContains = require('../../geom/circle/Contains');
|
||||
var CheckOverlapY = require('./CheckOverlapY');
|
||||
var Class = require('../../utils/Class');
|
||||
var CONST = require('./const');
|
||||
var Events = require('./events');
|
||||
var FuzzyEqual = require('../../math/fuzzy/Equal');
|
||||
var FuzzyGreaterThan = require('../../math/fuzzy/GreaterThan');
|
||||
var FuzzyLessThan = require('../../math/fuzzy/LessThan');
|
||||
var CheckOverlapY = require('./CheckOverlapY');
|
||||
var IntersectsRect = require('./IntersectsRect');
|
||||
var RadToDeg = require('../../math/RadToDeg');
|
||||
var Rectangle = require('../../geom/rectangle/Rectangle');
|
||||
var RectangleContains = require('../../geom/rectangle/Contains');
|
||||
|
@ -292,7 +293,7 @@ var Body = new Class({
|
|||
|
||||
/**
|
||||
* The minimum velocity a body can move before it won't rebound and is considered for sleep.
|
||||
* The default is 10 but you may wish to change this based on game type.
|
||||
* The default is 15 but you may wish to change this based on game type.
|
||||
*
|
||||
* @name Phaser.Physics.Arcade.Body#minVelocity
|
||||
* @type {Phaser.Math.Vector2}
|
||||
|
@ -316,7 +317,8 @@ var Body = new Class({
|
|||
|
||||
this.sleepIterations = 60;
|
||||
|
||||
this.forcePosition = false;
|
||||
// 0 = none, 1 = soft block, 2 = hard block
|
||||
this.forcePosition = 0;
|
||||
|
||||
/**
|
||||
* The Body's absolute maximum change in position, in pixels per step.
|
||||
|
@ -978,7 +980,7 @@ var Body = new Class({
|
|||
this.overlapY = 0;
|
||||
|
||||
this.embedded = false;
|
||||
this.forcePosition = false;
|
||||
this.forcePosition = 0;
|
||||
|
||||
// Updates the transform values
|
||||
this.updateBounds();
|
||||
|
@ -1017,7 +1019,7 @@ var Body = new Class({
|
|||
this.prevVelocity.set(0);
|
||||
this.speed = 0;
|
||||
|
||||
this.forcePosition = true;
|
||||
// this.forcePosition = true;
|
||||
|
||||
var worldBlocked = this.worldBlocked;
|
||||
|
||||
|
@ -1028,10 +1030,12 @@ var Body = new Class({
|
|||
if (worldBlocked.down)
|
||||
{
|
||||
this.bottom = worldBounds.bottom;
|
||||
this.forcePosition = 2;
|
||||
}
|
||||
else if (worldBlocked.up)
|
||||
{
|
||||
this.y = worldBounds.y;
|
||||
this.forcePosition = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1123,7 +1127,7 @@ var Body = new Class({
|
|||
this.checkWorldRebound();
|
||||
}
|
||||
|
||||
if (!this.forcePosition)
|
||||
if (this.forcePosition !== 2)
|
||||
{
|
||||
position.x += this.getMoveX(velocity.x * delta);
|
||||
position.y += this.getMoveY(velocity.y * delta);
|
||||
|
@ -1300,16 +1304,6 @@ var Body = new Class({
|
|||
|
||||
var gameObject = this.gameObject;
|
||||
|
||||
// var newVelocityY = Math.abs(this.velocity.y);
|
||||
|
||||
// if (newVelocityY < this.minVelocity.y)
|
||||
// {
|
||||
// if (this.isBlockedDown())
|
||||
// {
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
if (this.moves)
|
||||
{
|
||||
var mx = this.deltaMax.x;
|
||||
|
@ -1357,9 +1351,9 @@ var Body = new Class({
|
|||
this.facing = CONST.FACING_DOWN;
|
||||
}
|
||||
|
||||
if (this.forcePosition)
|
||||
if (this.forcePosition !== 0)
|
||||
{
|
||||
// console.log(this.world._frame, this.gameObject.name, 'forcePosition', this.y);
|
||||
console.log(this.world._frame, this.gameObject.name, 'forcePosition', this.y);
|
||||
|
||||
gameObject.x = this.x;
|
||||
gameObject.y = this.y;
|
||||
|
@ -2191,18 +2185,12 @@ var Body = new Class({
|
|||
|
||||
this.setBlocker(by);
|
||||
|
||||
// if (forceY && !this.worldBlocked.up)
|
||||
// if (forceY && !this.worldBlocked.up && this.velocity.y <= 0)
|
||||
if (forceY && !this.worldBlocked.up && this.velocity.y <= 0)
|
||||
if (forceY && this.forcePosition !== 2)
|
||||
{
|
||||
console.log(this.world._frame, this.gameObject.name, 'setBlockedUp');
|
||||
|
||||
this.y = by.bottom;
|
||||
this.forcePosition = true;
|
||||
|
||||
if (this.bounce.y === 0 && this.isGravityBlockedY())
|
||||
if (IntersectsRect(this, by))
|
||||
{
|
||||
this.velocity.y = 0;
|
||||
this.y = by.bottom;
|
||||
this.forcePosition = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2227,19 +2215,12 @@ var Body = new Class({
|
|||
// GetOverlapY = calls this, setting 'true' for forcing Y
|
||||
// SeparateY = calls this, not setting anything, so 'true' for forcing Y
|
||||
|
||||
// if (forceY && !this.worldBlocked.down)
|
||||
// if (forceY && !this.worldBlocked.down && this.velocity.y >= 0)
|
||||
// if (!this.worldBlocked.down && this.velocity.y >= 0)
|
||||
if (forceY && !this.worldBlocked.down && this.velocity.y >= 0)
|
||||
if (forceY && this.forcePosition !== 2)
|
||||
{
|
||||
console.log(this.world._frame, this.gameObject.name, 'setBlockedDown');
|
||||
|
||||
this.bottom = by.y;
|
||||
this.forcePosition = true;
|
||||
|
||||
if (this.bounce.y === 0 && this.isGravityBlockedY())
|
||||
if (IntersectsRect(this, by))
|
||||
{
|
||||
this.velocity.y = 0;
|
||||
this.bottom = by.y;
|
||||
this.forcePosition = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2280,7 +2261,7 @@ var Body = new Class({
|
|||
if (forceY !== undefined && !this.wasBlocked.up)
|
||||
{
|
||||
this.y = forceY;
|
||||
this.forcePosition = true;
|
||||
this.forcePosition = 2;
|
||||
}
|
||||
|
||||
return this;
|
||||
|
@ -2297,7 +2278,7 @@ var Body = new Class({
|
|||
{
|
||||
console.log(this.gameObject.name, 'world blocked down + position');
|
||||
this.bottom = forceY;
|
||||
this.forcePosition = true;
|
||||
this.forcePosition = 2;
|
||||
}
|
||||
|
||||
return this;
|
||||
|
|
|
@ -62,8 +62,8 @@ var GetOverlapY = function (body1, body2, overlapOnly, bias)
|
|||
body1.setTouchingDown();
|
||||
body2.setTouchingUp();
|
||||
|
||||
body1.setBlockedDown(body2);
|
||||
body2.setBlockedUp(body1);
|
||||
body1.setBlockedDown(body2, intersects);
|
||||
body2.setBlockedUp(body1, intersects);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -85,8 +85,8 @@ var GetOverlapY = function (body1, body2, overlapOnly, bias)
|
|||
body1.setTouchingUp();
|
||||
body2.setTouchingDown();
|
||||
|
||||
body1.setBlockedUp(body2);
|
||||
body2.setBlockedDown(body1);
|
||||
body1.setBlockedUp(body2, intersects);
|
||||
body2.setBlockedDown(body1, intersects);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,9 +51,15 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
|
|||
var body1Immovable = (body1.physicsType === CONST.STATIC_BODY || body1.immovable);
|
||||
var body2Immovable = (body2.physicsType === CONST.STATIC_BODY || body2.immovable);
|
||||
|
||||
console.log('');
|
||||
console.log('frame', body1.world._frame);
|
||||
console.log('body1', body1.gameObject.name, 'overlaps body2', body2.gameObject.name, 'on the', ((topFace) ? 'top' : 'bottom'));
|
||||
|
||||
// Can't separate two immovable bodies, or a body with its own custom separation logic
|
||||
if (!intersects || overlapOnly || (body1Immovable && body2Immovable) || body1.customSeparateY || body2.customSeparateY)
|
||||
{
|
||||
console.log('SeparateY aborted');
|
||||
|
||||
// return true if there was some overlap, otherwise false.
|
||||
return ((intersects && overlap !== 0) || (body1.embedded && body2.embedded));
|
||||
}
|
||||
|
@ -65,10 +71,6 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
|
|||
var ny1 = v1;
|
||||
var ny2 = v2;
|
||||
|
||||
console.log('');
|
||||
console.log('frame', body1.world._frame);
|
||||
console.log('body1', body1.gameObject.name, 'overlaps body2', body2.gameObject.name, 'on the', ((topFace) ? 'top' : 'bottom'));
|
||||
|
||||
// At this point, the velocity from gravity, world rebounds, etc has been factored in.
|
||||
// The body is moving the direction it wants to, but may be blocked and rebound.
|
||||
|
||||
|
@ -98,10 +100,8 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
|
|||
console.log('resolution 1');
|
||||
console.log('pre-impact v = body1', v1, 'body2', v2);
|
||||
console.log('post-impact v = body1', ny1, 'body2', ny2);
|
||||
|
||||
// console.log('pre-impact y = body1', body1.gameObject.y, 'body2', body2.gameObject.y);
|
||||
// console.log('sleeping? = body1', body1.sleeping, 'body2', body2.sleeping);
|
||||
// console.log('wb = body1', body1.worldBlocked.down, 'body2', body2.worldBlocked.down);
|
||||
console.log('pre-impact y = body1', body1.gameObject.y, 'body2', body2.gameObject.y);
|
||||
console.log('wb = body1', body1.worldBlocked.down, 'body2', body2.worldBlocked.down);
|
||||
|
||||
// console.log('avg', avg);
|
||||
// console.log('nv', nv1, nv2);
|
||||
|
@ -141,8 +141,11 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
|
|||
console.log('resolution 3');
|
||||
console.log('pre-impact v = body1', v1, 'body2', v2);
|
||||
console.log('post-impact v = body1', ny1, 'body2', ny2);
|
||||
console.log('pre-impact by = body1', body1.y, 'body2', body2.y);
|
||||
console.log('pre-impact gy = body1', body1.gameObject.y, 'body2', body2.gameObject.y);
|
||||
console.log('wb = body1', body1.worldBlocked.down, 'body2', body2.worldBlocked.down);
|
||||
console.log('sleeping? = body1', body1.sleeping, 'body2', body2.sleeping);
|
||||
}
|
||||
}
|
||||
else if (moving1 && !moving2)
|
||||
{
|
||||
// Body2 is immovable, so adjust body1 speed
|
||||
|
@ -151,8 +154,10 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
|
|||
console.log('resolution 4');
|
||||
console.log('pre-impact v = body1', v1, 'body2', v2);
|
||||
console.log('post-impact v = body1', ny1, 'body2', ny2);
|
||||
console.log('pre-impact y = body1', body1.gameObject.y, 'body2', body2.gameObject.y);
|
||||
console.log('wb = body1', body1.worldBlocked.down, 'body2', body2.worldBlocked.down);
|
||||
console.log('sleeping? = body1', body1.sleeping, 'body2', body2.sleeping);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log('neither moving, or both immovable');
|
||||
|
@ -211,6 +216,22 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
|
|||
return true;
|
||||
}
|
||||
|
||||
// FLip flop?
|
||||
var flip1 = (v1 < 0 && ny1 > 0) || (v1 > 0 && ny1 < 0);
|
||||
var flip2 = (v2 < 0 && ny2 > 0) || (v2 > 0 && ny2 < 0);
|
||||
|
||||
if (!body1.sleeping && flip1 && Math.abs(ny1) < body1.minVelocity.y)
|
||||
{
|
||||
console.log('body1 flip vel too small, zeroing');
|
||||
ny1 = 0;
|
||||
}
|
||||
|
||||
if (!body2.sleeping && flip2 && Math.abs(ny2) < body2.minVelocity.y)
|
||||
{
|
||||
console.log('body2 flip vel too small, zeroing');
|
||||
ny2 = 0;
|
||||
}
|
||||
|
||||
// By this stage the bodies have their separation distance calculated (stored in totalA/B)
|
||||
// and they have their new post-impact velocity. So now we need to work out block state based on direction.
|
||||
|
||||
|
@ -228,7 +249,7 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
|
|||
}
|
||||
else
|
||||
{
|
||||
body1.y += totalA;
|
||||
body1.y += body1.getMoveY(totalA);
|
||||
console.log('ny1 < 0 topface add', body1.y);
|
||||
}
|
||||
}
|
||||
|
@ -242,7 +263,7 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
|
|||
}
|
||||
else
|
||||
{
|
||||
body1.y += totalA;
|
||||
body1.y += body1.getMoveY(totalA);
|
||||
console.log('ny1 < 0 bottomface add', body1.y);
|
||||
}
|
||||
}
|
||||
|
@ -268,7 +289,7 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
|
|||
}
|
||||
else
|
||||
{
|
||||
body1.y += totalA;
|
||||
body1.y += body1.getMoveY(totalA);
|
||||
console.log('ny1 > 0 topface add', body1.y);
|
||||
}
|
||||
}
|
||||
|
@ -282,7 +303,7 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
|
|||
}
|
||||
else
|
||||
{
|
||||
body1.y += totalA;
|
||||
body1.y += body1.getMoveY(totalA);
|
||||
console.log('ny1 > 0 bottomface add', body1.y);
|
||||
}
|
||||
}
|
||||
|
@ -307,8 +328,8 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
|
|||
}
|
||||
else
|
||||
{
|
||||
body1.y += totalA;
|
||||
console.log('body1 stationary topface add', body1.y);
|
||||
console.log('body1 stationary topface add', body1.y, 'ta', totalA, (body1.y + totalA));
|
||||
body1.y += body1.getMoveY(totalA);
|
||||
}
|
||||
}
|
||||
else if (bottomFace)
|
||||
|
@ -321,7 +342,7 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
|
|||
}
|
||||
else
|
||||
{
|
||||
body1.y += totalA;
|
||||
body1.y += body1.getMoveY(totalA);
|
||||
console.log('body1 stationary bottomface add', body1.y);
|
||||
}
|
||||
}
|
||||
|
@ -341,7 +362,7 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
|
|||
}
|
||||
else
|
||||
{
|
||||
body2.y += totalB;
|
||||
body2.y += body2.getMoveY(totalB);
|
||||
console.log('ny2 < 0 topface add', body2.y);
|
||||
}
|
||||
}
|
||||
|
@ -355,7 +376,7 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
|
|||
}
|
||||
else
|
||||
{
|
||||
body2.y += totalB;
|
||||
body2.y += body2.getMoveY(totalB);
|
||||
console.log('ny2 < 0 bottomface add', body2.y);
|
||||
}
|
||||
}
|
||||
|
@ -381,7 +402,7 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
|
|||
}
|
||||
else
|
||||
{
|
||||
body2.y += totalB;
|
||||
body2.y += body2.getMoveY(totalB);
|
||||
console.log('ny2 > 0 topface add', body2.y);
|
||||
}
|
||||
}
|
||||
|
@ -395,7 +416,7 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
|
|||
}
|
||||
else
|
||||
{
|
||||
body2.y += totalB;
|
||||
body2.y += body2.getMoveY(totalB);
|
||||
console.log('ny2 > 0 bottomface add', body2.y);
|
||||
}
|
||||
}
|
||||
|
@ -420,7 +441,7 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
|
|||
}
|
||||
else
|
||||
{
|
||||
body2.y += totalB;
|
||||
body2.y += body2.getMoveY(totalB);
|
||||
console.log('body2 stationary topface add', body2.y);
|
||||
}
|
||||
}
|
||||
|
@ -434,7 +455,7 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
|
|||
}
|
||||
else
|
||||
{
|
||||
body2.y += totalB;
|
||||
body2.y += body2.getMoveY(totalB);
|
||||
console.log('body2 stationary bottomface add', body2.y);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue