cocos角色在载具内移动

update(deltaTime: number) {

        //更新子碰撞体的位置

        this.ff4.setPosition(this.ff4.position)

        this.ff3.setPosition(this.ff3.position)

        this.ff2.setPosition(this.ff2.position)

        this.ff1.setPosition(this.ff1.position)

        this.ff5.setPosition(this.ff5.position)

        this.ff6.setPosition(this.ff6.position)

        this.ff7.setPosition(this.ff7.position)

        this.ff8.setPosition(this.ff8.position)

        this.ff9.setPosition(this.ff9.position)

        this.ff10.setPosition(this.ff10.position)

        this.ff11.setPosition(this.ff11.position)

        this.ff12.setPosition(this.ff12.position)

   

        //载具的移动

        // 根据自身方向,转化方向

        this.res1 = new Vec3(0, 0, this.sp2);

        //获取节点的本地化局部旋转方向,1:返回值,2:需要转换的方向向量,3:当前本地旋转

        Vec3.transformQuat(this.res1, this.res1, this.node.getWorldRotation());

        this.node.getComponent(RigidBody).setLinearVelocity(v3(this.res1.x, this.sp1, this.res1.z))

        this.node.getComponent(RigidBody).setAngularVelocity(v3(0,this.sp3,0))

       

       

    }

update(deltaTime: number) {

        // 根据自身方向,转化方向

        this.res1 = new Vec3(this.x1 * this.sp1 * deltaTime, 0, this.z1 * this.sp1 * deltaTime);

        //获取节点的本地化局部旋转方向,1:返回值,2:需要转换的方向向量,3:当前本地旋转

        Vec3.transformQuat(this.res1, this.res1, this.node.getWorldRotation());

        //移动方式的切换开关,获取组件开关,开启或关闭

        //this.characterController.enabled = false

        //this.node.getComponent(CapsuleCollider).enabled = true

        //在载具外移动的方式

        if(this.characterController.enabled && !this.node.getComponent(CapsuleCollider).enabled){

            this.characterController.move(v3(this.res1.x, -0.2, this.res1.z));

        }

        //在载具内移动的方式

        if(this.node.getComponent(CapsuleCollider).enabled && !this.characterController.enabled){

            this.node.setPosition(this.node.position)

            this.node.setWorldPosition(this.res1.x+this.node.worldPosition.x, this.node.worldPosition.y, this.res1.z+this.node.worldPosition.z)

        }

    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值