Twin Stick射击游戏控制器问题c#unity

时间:2013-06-27 08:38:03

标签: c# unity3d

我正在学习Unity和C#。

我尝试使用我的Xbox键盘的左右拇指杆制作顶视图射击游戏。我的角色用左手拇指在x和z轴上正确移动。但是,使用右拇指杆在y轴上旋转喷枪不能正常工作,它会卡在角度(45°,135°,225°,315°)。我无法顺利轮换..

using UnityEngine;
using System.Collections;

CharacterMotor controller;
public Transform player_turret;
public float deadzone = 0.25f;
private Quaternion desireRotation;

void  Update (){
    CharacterController controller = GetComponent<CharacterController>();
    moveDirection = new Vector3(Input.GetAxis("Horizontal")*speed*Time.deltaTime, 
                                0, 
                                Input.GetAxis("Vertical")*speed*Time.deltaTime);
    moveDirection = transform.TransformDirection(moveDirection);
    controller.Move(moveDirection);

    //right stick dead zone
    Vector2 shootDirection = new Vector2(Input.GetAxis("FireHorizontal"),     
                                         Input.GetAxis("FireVertical"));
    if(shootDirection.magnitude < deadzone){
        shootDirection = Vector2.zero;
    }else
    {
        Vector3 shootRotation = new Vector3(shootDirection.x, 0, shootDirection.y);
        desireRotation = Quaternion.LookRotation(shootRotation);
        player_turret.rotation = desireRotation;
        if((Time.time >= nextFireTime) && Input.GetButton("Button A")){
            FireProjectile();
        }
    }
}

0 个答案:

没有答案