修复ArcadeRigidbody不触发OnEntityTransform事件
This commit is contained in:
@@ -127,7 +127,7 @@ module es {
|
||||
*/
|
||||
public addImpulse(force: Vector2) {
|
||||
if (!this.isImmovable) {
|
||||
this.velocity.add(Vector2.multiplyScaler(force, 100000)
|
||||
this.velocity = Vector2.add(this.velocity, Vector2.multiplyScaler(force, 100000)
|
||||
.multiplyScaler(this._inverseMass * Time.deltaTime * Time.deltaTime));
|
||||
}
|
||||
}
|
||||
@@ -151,9 +151,9 @@ module es {
|
||||
}
|
||||
|
||||
if (this.shouldUseGravity)
|
||||
this.velocity.add(Vector2.multiplyScaler(Physics.gravity, Time.deltaTime));
|
||||
this.velocity = Vector2.add(this.velocity, Vector2.multiplyScaler(Physics.gravity, Time.deltaTime));
|
||||
|
||||
this.entity.position = this.entity.position.add(Vector2.multiplyScaler(this.velocity, Time.deltaTime));
|
||||
this.entity.position = Vector2.add(this.entity.position, Vector2.multiplyScaler(this.velocity, Time.deltaTime));
|
||||
let collisionResult = new CollisionResult();
|
||||
|
||||
// 捞取我们在新的位置上可能会碰撞到的任何东西
|
||||
@@ -172,7 +172,7 @@ module es {
|
||||
this.processCollision(neighborRigidbody, collisionResult.minimumTranslationVector);
|
||||
} else {
|
||||
// 没有ArcadeRigidbody,所以我们假设它是不动的,只移动我们自己的
|
||||
this.entity.position = this.entity.position.subtract(collisionResult.minimumTranslationVector);
|
||||
this.entity.position = Vector2.subtract(this.entity.position, collisionResult.minimumTranslationVector);
|
||||
let relativeVelocity = this.velocity.clone();
|
||||
this.calculateResponseVelocity(relativeVelocity, collisionResult.minimumTranslationVector, relativeVelocity);
|
||||
this.velocity.add(relativeVelocity);
|
||||
@@ -188,12 +188,12 @@ module es {
|
||||
*/
|
||||
public processOverlap(other: ArcadeRigidbody, minimumTranslationVector: Vector2) {
|
||||
if (this.isImmovable) {
|
||||
other.entity.position = other.entity.position.add(minimumTranslationVector);
|
||||
other.entity.position = Vector2.add(other.entity.position, minimumTranslationVector);
|
||||
} else if (other.isImmovable) {
|
||||
this.entity.position = this.entity.position.subtract(minimumTranslationVector);
|
||||
other.entity.position = Vector2.subtract(other.entity.position, minimumTranslationVector);
|
||||
} else {
|
||||
this.entity.position = this.entity.position.subtract(Vector2.multiplyScaler(minimumTranslationVector, 0.5));
|
||||
other.entity.position = other.entity.position.add(Vector2.multiplyScaler(minimumTranslationVector, 0.5));
|
||||
this.entity.position = Vector2.subtract(this.entity.position, Vector2.multiplyScaler(minimumTranslationVector, 0.5));
|
||||
other.entity.position = Vector2.add(other.entity.position, Vector2.multiplyScaler(minimumTranslationVector, 0.5));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,8 +215,8 @@ module es {
|
||||
let ourResponseFraction = this._inverseMass / totalinverseMass;
|
||||
let otherResponseFraction = other._inverseMass / totalinverseMass;
|
||||
|
||||
this.velocity.add(Vector2.multiplyScaler(relativeVelocity, ourResponseFraction));
|
||||
other.velocity.subtract(Vector2.multiplyScaler(relativeVelocity, otherResponseFraction));
|
||||
this.velocity = Vector2.add(this.velocity, Vector2.multiplyScaler(relativeVelocity, ourResponseFraction));
|
||||
other.velocity = Vector2.subtract(other.velocity, Vector2.multiplyScaler(relativeVelocity, otherResponseFraction));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -59,10 +59,10 @@ module es {
|
||||
}
|
||||
|
||||
public get bounds(): Rectangle {
|
||||
// if (this._isPositionDirty || this._isRotationDirty) {
|
||||
if (this._isPositionDirty || this._isRotationDirty) {
|
||||
this.shape.recalculateBounds(this);
|
||||
// this._isPositionDirty = this._isRotationDirty = false;
|
||||
// }
|
||||
this._isPositionDirty = this._isRotationDirty = false;
|
||||
}
|
||||
|
||||
return this.shape.bounds;
|
||||
}
|
||||
@@ -221,7 +221,7 @@ module es {
|
||||
result.collider = collider;
|
||||
|
||||
// 将图形位置返回到检查前的位置
|
||||
this.entity.position = oldPosition;
|
||||
this.entity.position = oldPosition.clone();
|
||||
|
||||
return didCollide;
|
||||
}
|
||||
@@ -270,7 +270,7 @@ module es {
|
||||
}
|
||||
|
||||
// 将形状位置返回到检查之前的位置
|
||||
this.shape.position = oldPosition;
|
||||
this.shape.position = oldPosition.clone();
|
||||
|
||||
return didCollide;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ module es {
|
||||
/**
|
||||
* 值会根据位置、旋转和比例自动重新计算
|
||||
*/
|
||||
public _localTransform: Matrix2D;
|
||||
public _localTransform: Matrix2D = Matrix2D.identity;
|
||||
/**
|
||||
* 值将自动从本地和父矩阵重新计算。
|
||||
*/
|
||||
@@ -426,8 +426,8 @@ module es {
|
||||
this._localScaleDirty = false;
|
||||
}
|
||||
|
||||
this._localTransform = this._scaleMatrix.multiply(this._rotationMatrix);
|
||||
this._localTransform = this._localTransform.multiply(this._translationMatrix);
|
||||
es.Matrix2D.multiply(this._scaleMatrix, this._rotationMatrix, this._localTransform);
|
||||
es.Matrix2D.multiply(this._localTransform, this._translationMatrix, this._localTransform);
|
||||
|
||||
if (this.parent == null) {
|
||||
this._worldTransform = this._localTransform;
|
||||
@@ -440,8 +440,7 @@ module es {
|
||||
}
|
||||
|
||||
if (this.parent != null) {
|
||||
this._worldTransform = this._localTransform.multiply(this.parent._worldTransform);
|
||||
|
||||
es.Matrix2D.multiply(this._localTransform, this.parent._worldTransform, this._worldTransform);
|
||||
this._rotation = this._localRotation + this.parent._rotation;
|
||||
this._scale = Vector2.multiply(this.parent._scale, this._localScale);
|
||||
this._worldInverseDirty = true;
|
||||
@@ -480,8 +479,8 @@ module es {
|
||||
* @param transform
|
||||
*/
|
||||
public copyFrom(transform: Transform) {
|
||||
this._position = transform.position;
|
||||
this._localPosition = transform._localPosition;
|
||||
this._position = transform.position.clone();
|
||||
this._localPosition = transform._localPosition.clone();
|
||||
this._rotation = transform._rotation;
|
||||
this._localRotation = transform._localRotation;
|
||||
this._scale = transform._scale;
|
||||
|
||||
Reference in New Issue
Block a user