Hey there! I’ve built and run an early version of my game, and it works great using my wireless keyboard. I’ve tested it on other computers with different keyboards, and it works with them too.
I sent it to my friend, and almost everything works as intended except for one major thing, the player character refuses to move based on the Input.GetAxisRaw function. What’s weird is that I have a child Empty GameObject attached to the player that plays footstep noises when the player presses a direction IS playing.
So the footsteps recognize the input, but the player movement script doesn’t. What’s up with that?
Can a monitor’s refresh rate affect the GetAxisRaw function? I’ve been testing on a 60hz monitor, where my friend is using a 165hz monitor. That’s like the only thing I can think of that could affect the input.
If anyone has any insight or advice, that’d be much appreciated!
EDIT #2:
Here’s my movement script:
void Update() {
//input
Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
Vector2 inputDir = input.normalized;
bool running = Input.GetKey(KeyCode.LeftShift);
Move(inputDir, running);
}
void Move(Vector3 input, bool running) {
if (inputDir != Vector2.zero) //if input direction returns a value that isn't (0,0)
{
float targetRotation = Mathf.Atan2(inputDir.x, inputDir.y) * Mathf.Rad2Deg + cameraT.eulerAngles.y; // set target rotation towards input direction (x,y), find the angles relative to the camera
transform.eulerAngles = Vector3.up * Mathf.SmoothDampAngle(transform.eulerAngles.y, targetRotation, ref turnSmoothVelocity, GetModifiedSmoothTime(turnSmoothTime)); // rotate player object smoothly
}
float targetSpeed = ((running) & haveStamina ? runSpeed : walkSpeed) * inputDir.magnitude; //if running = true, set target speed to runspeed. Otherwise set target speed to walkspeed * inputdirection
currentSpeed = Mathf.SmoothDamp(currentSpeed, targetSpeed, ref speedSmoothVelocity, GetModifiedSmoothTime(speedSmoothTime)); //smoothly ease our current speed into the target speed
velocityY += Time.deltaTime * gravity; //vertical velocity is equal to the value of gravity multiplied by time
Vector3 velocity = transform.forward * currentSpeed + Vector3.up * velocityY;
controller.Move(velocity * Time.deltaTime);
currentSpeed = new Vector2(controller.velocity.x, controller.velocity.z).magnitude;
}
And here’s the footstep sound empty object :
void Update() {
GetState();
PlayAudio();
}
void GetState()
{
Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
Vector2 inputDir = input.normalized;
if (inputDir != Vector2.zero)
{
if (Input.GetKey("left shift") && !overheated)
{
audioPlayer.pitch = 1.3f;
isRunning = true;
}
else
{
isRunning = true;
audioPlayer.pitch = 1f;
}
}
else
{
isRunning = false;
audioPlayer.pitch = 1f;
}
}
Also something else that came up was that my attempts to limit the application framerate to 30 failed with my friend’s monitor. Apparently
void Awake()
{
QualitySettings.vSyncCount = 2;
Application.targetFrameRate = 30;
}
Doesn’t work either. I’m so confused with why certain monitors can affect performance? Especially when I’m limiting the framerate.