使用摇杆制作瞄准后发射的技能按钮 人物无法改变面朝方向

[复制链接]
109 |1
吖嗡嗡 发表于 2024-4-17 23:56:11 | 显示全部楼层 |阅读模式
UI 控件-摇杆 | 产品手册 (ark.online) 最底部的示例


使用如下代码无法实现人物 面朝方向的改动,_rotation有变化,感觉是这个变量的问题        
myCharacter.movementAxisDirection = this._rotation;

@UIBind('')
export default class DefaultUI extends UIScript {
    private character: Character;
    private anim1 = null;

    player: Player;
    _Joystick: VirtualJoystickPanel;
    _rotation:Vector

    /** 仅在游戏时间对非模板实例调用一次 */
    protected  onStart() {
        //设置能否每帧触发onUpdate
        this.canUpdate = false;

        //找到对应的跳跃按钮
        const jumpBtn = this.uiWidgetBase.findChildByPath('RootCanvas/Button_Jump') as Button;

        //点击跳跃按钮,异步获取人物后执行跳跃
        jumpBtn.onPressed.add(()=>{
            if (this.character) {
                this.character.jump();
            } else {
                Player.asyncGetLocalPlayer().then((player) => {
                    this.character = player.character;
                    //角色执行跳跃功能
                    this.character.jump();
                });
            }
        });

        this.InitEvents();

    }

    InitEvents() {

        //找到对应的摇杆
        this._Joystick = this.uiWidgetBase.findChildByPath('RootCanvas/JoystickAim') as VirtualJoystickPanel

        //按下摇杆后调整FOV和灵敏度
        this._Joystick.onJoyStickDown.add(() => {
            Camera.currentCamera.fov=80
            this._Joystick.inputScale=(new Vector2(0.2, 0.2))
        });


        //转动摇杆的时候记录方向,并修改角色面朝方向
        this._Joystick.onInputDir.add((vec : Vector2)=>{

            if(vec.length > 0){
                this._rotation = new Vector(0,0,Camera.currentCamera.worldTransform.rotation.z-Math.atan2(vec.normalized.y, vec.normalized.x)/Math.PI*180+90)
                // 获取当前客户端的玩家(自己)
                let myPlayer = Player.localPlayer;
                // // 获取当前玩家控制的角色
                let myCharacter = myPlayer.character;
                myCharacter.moveFacingDirection = 1;
                myCharacter.movementAxisDirection = this._rotation;     
            }
        });


        // 松开摇杆的时候,发送射击事件和方向,并把FOV和灵敏度调回去
        this._Joystick.onJoyStickUp.add(() => {
            // Event.dispatchToServer("_magicattacking",this._rotation);
            Camera.currentCamera.fov=90
            this._Joystick.inputScale=(new Vector2(0.5, 0.5))
        });
    }
}

回复

使用道具 举报

复读机读复读机 发表于 2024-4-18 10:30:16 | 显示全部楼层
可以修改character.worldTransform.rotation
20240418103048_rec_.gif
  1. this._Joystick = this.uiWidgetBase.findChildByPath('RootCanvas/JoystickAim') as VirtualJoystickPanel

  2. //按下摇杆后调整FOV和灵敏度
  3. this._Joystick.onJoyStickDown.add(() => {
  4. Camera.currentCamera.fov = 80
  5. this._Joystick.inputScale = (new Vector2(0.2, 0.2))
  6. });


  7. //转动摇杆的时候记录方向,并修改角色面朝方向
  8. this._Joystick.onInputDir.add((vec: Vector2) => {
  9. console.log("bbbbbb");

  10. if (vec) {
  11.         console.log("aaaaa");

  12.         this._rotation = new Rotation(0, 0, Camera.currentCamera.worldTransform.rotation.z - Math.atan2(vec.normalized.y, vec.normalized.x) / Math.PI * 180 + 90)
  13.         // 获取当前客户端的玩家(自己)
  14.         let myPlayer = Player.localPlayer;
  15.         // // 获取当前玩家控制的角色
  16.         let myCharacter = myPlayer.character;
  17.         myCharacter.worldTransform.rotation = this._rotation
  18. }
  19. });
复制代码
回复

使用道具 举报

热门版块
快速回复 返回顶部 返回列表