[LayaAirIDE 2.0]判断玩家在地面还在空中
跑酷游戏中判断玩家是否在空中还是地面上来检测是否可以二段跳
判断脚下物体代码
onGround():any{
let bc:Laya.BoxColliderShape = this.rigidbody.colliderShape as Laya.BoxColliderShape
let y:number = this.transform.position.y-bc.sizeY/2 - 0.05
let vec3:Laya.Vector3 = new Laya.Vector3(this.transform.position.x,y,this.transform.position.z);
var ray = new Laya.Ray(vec3,new Laya.Vector3(0,0,1));
(this.owner.scene as Laya.Scene3D).physicsSimulation.rayCast(ray,this.outHitResult);
if(!this.outHitResult.succeeded){
return false;
}
return this.outHitResult.collider
}
然后使用方法
let obj = this.onGround()
let isGround = obj == this.rigidbody;
这样写,获取到的结果一直是false,就算已经在地面上跑了,都检测不到,求指点
判断脚下物体代码
onGround():any{
let bc:Laya.BoxColliderShape = this.rigidbody.colliderShape as Laya.BoxColliderShape
let y:number = this.transform.position.y-bc.sizeY/2 - 0.05
let vec3:Laya.Vector3 = new Laya.Vector3(this.transform.position.x,y,this.transform.position.z);
var ray = new Laya.Ray(vec3,new Laya.Vector3(0,0,1));
(this.owner.scene as Laya.Scene3D).physicsSimulation.rayCast(ray,this.outHitResult);
if(!this.outHitResult.succeeded){
return false;
}
return this.outHitResult.collider
}
然后使用方法
let obj = this.onGround()
let isGround = obj == this.rigidbody;
这样写,获取到的结果一直是false,就算已经在地面上跑了,都检测不到,求指点
没有找到相关结果
已邀请:
1 个回复
pabble
赞同来自: