//需要撞击的层
@property({type:physics.PhysicsGroup})
group:PhysicsGroup
start() {
//物理过程之后所触发的事件
director.on(Director.EVENT_AFTER_PHYSICS,this.raycast,this)
}
raycast(){
const tmpRay = geometry.Ray.create(this.node.worldPosition.x,this.node.worldPosition.y,this.node.worldPosition.z, 0, -1, 0)
if( PhysicsSystem.instance.raycastClosest(tmpRay, this.group, 0.5,this.queryTrigger)){
let ey = PhysicsSystem.instance.raycastClosestResult
//获取世界坐标系的撞击点
var y = ey.hitPoint.y
//获取撞击距离
var gf1 = ey.distance
console.log(y + "aaaaa")
console.log(gf1 +"ddddd")
this.node.worldPosition = v3(this.node.worldPosition.x,y+0.5,this.node.worldPosition.z)
}
}