贝塞尔曲线

This commit is contained in:
yhh
2020-07-17 11:07:57 +08:00
parent 13e7737cb9
commit 14cb9cd257
11 changed files with 431 additions and 5 deletions

View File

@@ -23,11 +23,12 @@ class Mover extends Component {
return null;
}
// 移动所有的非触发碰撞器并获得最近的碰撞
let colliders: Collider[] = this.entity.getComponents(Collider);
for (let i = 0; i < colliders.length; i ++){
let collider = colliders[i];
// 不检测触发器
// 不检测触发器 在我们移动后会重新访问它
if (collider.isTrigger)
continue;
@@ -63,13 +64,23 @@ class Mover extends Component {
return {collisionResult: collisionResult, motion: motion};
}
/**
* 将calculatemomovement应用到实体并更新triggerHelper
* @param motion
*/
public applyMovement(motion: Vector2){
// 移动实体到它的新位置,如果我们有一个碰撞,否则移动全部数量。当碰撞发生时,运动被更新
this.entity.position = Vector2.add(this.entity.position, motion);
// 对所有是触发器的碰撞器与所有宽相位碰撞器进行重叠检查。任何重叠都会导致触发事件。
if (this._triggerHelper)
this._triggerHelper.update();
}
/**
* 通过调用calculateMovement和applyMovement来移动考虑碰撞的实体;
* @param motion
*/
public move(motion: Vector2){
let movementResult = this.calculateMovement(motion);
let collisionResult = movementResult.collisionResult;

View File

@@ -0,0 +1,56 @@
/**
* 只向itriggerlistener报告冲突的移动器
* 该对象将始终移动完整的距离
*/
class ProjectileMover extends Component {
private _tempTriggerList: ITriggerListener[] = [];
private _collider: Collider;
public onAddedToEntity(){
this._collider = this.entity.getComponent<Collider>(Collider);
if (!this._collider)
console.warn("ProjectileMover has no Collider. ProjectilMover requires a Collider!");
}
/**
* 移动考虑碰撞的实体
* @param motion
*/
public move(motion: Vector2): boolean{
if (!this._collider)
return false;
let didCollide = false;
// 获取我们在新位置可能发生碰撞的任何东西
this.entity.position = Vector2.add(this.entity.position, motion);
// 获取任何可能在新位置发生碰撞的东西
let neighbors = Physics.boxcastBroadphase(this._collider.bounds, this._collider.collidesWithLayers);
for (let i = 0; i < neighbors.colliders.length; i ++){
let neighbor = neighbors.colliders[i];
if (this._collider.overlaps(neighbor)){
didCollide = true;
this.notifyTriggerListeners(this._collider, neighbor);
}
}
return didCollide;
}
private notifyTriggerListeners(self: Collider, other: Collider){
// 通知我们重叠的碰撞器实体上的任何侦听器
other.entity.getComponents("ITriggerListener", this._tempTriggerList);
for (let i = 0; i < this._tempTriggerList.length; i ++){
this._tempTriggerList[i].onTriggerEnter(self, other);
}
this._tempTriggerList.length = 0;
// 通知此实体上的任何侦听器
this.entity.getComponents("ITriggerListener", this._tempTriggerList);
for (let i = 0; i < this._tempTriggerList.length; i ++){
this._tempTriggerList[i].onTriggerEnter(other, self);
}
this._tempTriggerList.length = 0;
}
}