Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How can I get a sensitivity from a game and implement it to mine?

Discussion in 'Scripting' started by Nowamm, Sep 12, 2020.

  1. Nowamm

    Nowamm

    Joined:
    Aug 24, 2018
    Posts:
    18
    I'm making sort of an fps trainer and I need to somehow get some game's sensitivity. For now I only want Valorant sens but if you would give me more then it will be appreciated.

    My code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Photon.Pun;
    5.  
    6. public class Look : MonoBehaviourPunCallbacks
    7. {
    8.     #region Variables
    9.     public static bool cursorLocked = true;
    10.  
    11.     public Transform player;
    12.     public Transform normalCam;
    13.     public Transform weaponCam;
    14.     public Transform weapon;
    15.  
    16.     public float xSensitivity;
    17.     public float ySensitivity;
    18.     public float maxAngle;
    19.  
    20.     private Quaternion camCenter;
    21.  
    22.     private ValueSender valueSender;
    23.     #endregion
    24.  
    25.     #region Monobehaviour Callbacks
    26.     void Start()
    27.     {
    28.         camCenter = normalCam.localRotation;
    29.     }
    30.  
    31.     void Update()
    32.     {
    33.         if (!photonView.IsMine) return;
    34.         if (Pause.paused) return;
    35.  
    36.         SetY();
    37.         SetX();
    38.  
    39.         weaponCam.rotation = normalCam.rotation;
    40.  
    41.         valueSender = FindObjectOfType<ValueSender>();
    42.         xSensitivity = valueSender.xSensitivity;
    43.         ySensitivity = valueSender.ySensitivity;
    44.     }
    45.     #endregion
    46.  
    47.     #region Private Methods
    48.     void SetY()
    49.     {
    50.         float t_input = Input.GetAxis("Mouse Y") * ySensitivity * Time.deltaTime;
    51.         Quaternion t_adj = Quaternion.AngleAxis(t_input, -Vector3.right);
    52.         Quaternion t_delta = normalCam.localRotation * t_adj;
    53.  
    54.         if (Quaternion.Angle(camCenter, t_delta) < maxAngle)
    55.         {
    56.             normalCam.localRotation = t_delta;
    57.         }
    58.  
    59.         weapon.rotation = normalCam.rotation;
    60.     }
    61.  
    62.     void SetX()
    63.     {
    64.         float t_input = Input.GetAxis("Mouse X") * xSensitivity * Time.deltaTime;
    65.         Quaternion t_adj = Quaternion.AngleAxis(t_input, Vector3.up);
    66.         Quaternion t_delta = player.localRotation * t_adj;
    67.         player.localRotation = t_delta;
    68.     }
    69.     #endregion
    70. }
    71.  
     
  2. Oskar_Kasprzak

    Oskar_Kasprzak

    Joined:
    Mar 26, 2016
    Posts:
    61
    I am not sure but doesnt sensitivity in games depends on user settings? Do you mean that you want to read sensitivity from installed game so it's the same?
     
  3. DaDonik

    DaDonik

    Joined:
    Jun 17, 2013
    Posts:
    258
    Without having the source code of Valorant, you have 0 chance of duplicating their sensitivity settings.
     
  4. Nowamm

    Nowamm

    Joined:
    Aug 24, 2018
    Posts:
    18
    Wdym?
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    Sensitivity is just numbers. Pick a number, if it works great. If it's too small, double it. Try again. If it's too sensitive, reduce it. Iterate. Succeed!
     
  6. Nowamm

    Nowamm

    Joined:
    Aug 24, 2018
    Posts:
    18
    Yes, I did that and it works only with one sensitivity and I don't know why. Maybe instead of doing
    Code (CSharp):
    1. float t_input = Input.GetAxis("Mouse Y") * ySensitivity * Time.deltaTime
    i'll do
    Code (CSharp):
    1. float t_input = Input.GetAxis("Mouse Y") + ySensitivity * Time.deltaTime
     
  7. Nowamm

    Nowamm

    Joined:
    Aug 24, 2018
    Posts:
    18
    Nvm it doesn't work. I'm lost :/