新增raycast射线

This commit is contained in:
yhh
2020-07-31 17:17:44 +08:00
parent 514572f291
commit 40fe7a57db
13 changed files with 1182 additions and 813 deletions

View File

@@ -0,0 +1,57 @@
module es {
export class RaycastHit {
/**
* 对撞机被射线击中
*/
public collider: Collider;
/**
* 撞击发生时沿射线的距离。
*/
public fraction: number = 0;
/**
* 从射线原点到碰撞点的距离
*/
public distance: number = 0;
/**
* 世界空间中光线击中对撞机表面的点
*/
public point: Vector2 = Vector2.zero;
/**
* 被射线击中的表面的法向量
*/
public normal: Vector2 = Vector2.zero;
/**
* 用于执行转换的质心。使其接触的形状的位置。
*/
public centroid: Vector2;
constructor(collider: Collider, fraction: number, distance: number, point: Vector2, normal: Vector2){
this.collider = collider;
this.fraction = fraction;
this.distance = distance;
this.point = point;
this.centroid = Vector2.zero;
}
public setValues(collider: Collider, fraction: number, distance: number, point: Vector2){
this.collider = collider;
this.fraction = fraction;
this.distance = distance;
this.point = point;
}
public reset(){
this.collider = null;
this.fraction = this.distance = 0;
}
public toString(){
return `[RaycastHit] fraction: ${this.fraction}, distance: ${this.distance}, normal: ${this.normal}, centroid: ${this.centroid}, point: ${this.point}`;
}
}
}