简体   繁体   English

修改Unity中PS3手柄的摇杆灵敏度

[英]Modify the sensitivity of the joysticks of a PS3 controller in Unity

Right now I am working in a project and I am testing it with my PS3 controller and some of the mechanics of the game is to dodge an enemy attack if the player moves the left stick once to the left or to the right, up or down.现在我正在做一个项目,我正在用我的 PS3 控制器测试它,游戏的一些机制是如果玩家向左或向右、向上或向下移动一次左摇杆来躲避敌人的攻击. And if the player moves the stick twice, the character will do a roll.如果玩家移动摇杆两次,角色将滚动。 But the sentitive that the stick has is too high that the player needs to do a very fast movement to dodge and if it is not fast enough it just rolls and keep rolling if the player hold the stick in one direction.但是摇杆的敏感度太高,玩家需要做一个非常快的移动来躲避,如果它不够快,它只会滚动并保持滚动,如果玩家朝一个方向握住棍子。

So here is the question: How can I change the sensitivity of the stick?那么问题来了:我怎样才能改变摇杆的灵敏度?

I tried changing the value in the Input Manager but it doesn't work (if I put a higher number the problem stays and if I put a lower number it does'nt work).我尝试更改输入管理器中的值,但它不起作用(如果我输入更高的数字,问题仍然存在,如果我输入更低的数字,则它不起作用)。

Input manager输入管理器

This is the code that I did to do the rolls:这是我做卷的代码:

#region Forward
        if (Input.GetAxis("Mouse Y") <= -0.1 && forwardRoll)
        {
            if (timeToRoll > 0)
            {
                animatorController.SetBool("RollForward", true);
                yield return new WaitForSeconds(0.01f);
                animatorController.SetBool("RollForward", false);

                forwardRoll = false;
            }
            else
            {
                forwardRoll = false;
            }
        }

        if (Input.GetAxis("Mouse Y") <= -0.1 && !forwardRoll)
        {
            forwardRoll = true;
            timeToRoll = 1f;
        }
        #endregion

This is for the Forward Roll, is the same for the other directions这是向前滚动,其他方向相同

Note: the Input.GetAxis("Mouse Y") returns a 0.1 as a higher value or -0.1 as the lower in the Y axis, the same for the X axis.注意: Input.GetAxis("Mouse Y")在 Y 轴返回 0.1 作为较高值或 -0.1 作为较低值,X 轴相同。

Thank you all, have a good day!谢谢大家,祝你有美好的一天!

All the values for an Axis are in interval [-1, 1]轴的所有值都在 [-1, 1] 区间内

so if you want to modify the sensivity of stick you could (for example) divide the zone in 10 or more parts and modify the return value used:因此,如果您想修改棒的灵敏度,您可以(例如)将区域划分为 10 个或更多部分并修改使用的返回值:

for example to add less senivity for an axis: you could do that:例如,为轴添加较少的敏感度:您可以这样做:

float x = Input.GetAxis("what you want") ;
if ( x > -0.1 && x < 0.1)  // less sensivity at deadzone
    x = 0;
else if (x > -0.3 && x < -0.2)
    x = -0.1;
else if
    and so on

then you use the value x to inject in your program and not the value of Input.GetAxis

so you could calibrate each zone with the value desired这样您就可以使用所需的值校准每个区域

you could do have a linear function different at each zone你可以在每个区域都有不同的线性函数

or apply a new function to the Axis.或将新功能应用于轴。

for example, you have lot of joystick curve HERE例如,你有很多的操纵杆曲线HERE

and if you choose the first curve如果你选择第一条曲线

f(x) = x*(s/9)+(x^5)*(9-s)/9 with s = 0, you have: f(x) = x*(s/9)+(x^5)*(9-s)/9 s = 0,你有:

f(x) = x^5 f(x) = x^5

for x in [0, 1] you have f(x) in [0,1]对于 [0, 1] 中的 x,您在 [0,1] 中有 f(x)

for x in [-1, 0] you have f(x) in [-1,0],对于 [-1, 0] 中的 x,您在 [-1,0] 中有 f(x),

so in program you could write:所以在程序中你可以写:

float x = Input.GetAxis("what you want");
x = Mathf.Pow( x, 5);

试试这个:如果玩家按下一个轴...开始 courutine.... 如果值为零,则检查 courutine 一小段时间,然后如果它在时间用完之前再次变成正数或负数...如果是这样,那么做桶如果值在指定时间内未更改,则滚动,然后躲避...您的问题不是敏感性...是逻辑...对不起,如果我不显示任何代码:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM