[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,就算已经在地面上跑了,都检测不到,求指点
已邀请:

pabble

赞同来自:

大意了,把0,0,1改成010就可以了

该问题目前已经被锁定, 无法添加新回复

商务合作
商务合作