Hi,
If I include runSpeed (even at very low values) my player runs left and right way too fast. If I omit runSpeed he runs too slow. How can I fix this?
Here is the relevant PlayerMovement.cs
code:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
[SerializeField] float runSpeed = 0.00001f;
[SerializeField] float jumpSpeed = 5f;
Vector2 moveInput;
Rigidbody2D myRigidbody;
Animator myAnimator;
CapsuleCollider2D playerCollider;
bool playerHasHorizontalSpeed;
void Start()
{
myRigidbody = GetComponent<Rigidbody2D>();
myAnimator = GetComponent<Animator>();
playerCollider = GetComponent<CapsuleCollider2D>();
}
void Update()
{
playerHasHorizontalSpeed = Mathf.Abs(myRigidbody.velocity.x) > Mathf.Epsilon;
Run();
FlipSprite();
}
void OnMove(InputValue value)
{
moveInput = value.Get<Vector2>();
}
void OnJump(InputValue value)
{
if(playerCollider.IsTouchingLayers(LayerMask.GetMask("Ground")) && value.isPressed)
{
myRigidbody.velocity += new Vector2 (0f, jumpSpeed);
}
}
void Run()
{
Vector2 playerVelocity = new Vector2 (moveInput.x * runSpeed, myRigidbody.velocity.y);
myRigidbody.velocity = playerVelocity;
myAnimator.SetBool("isRunning", playerHasHorizontalSpeed);
}
void FlipSprite()
{
if(playerHasHorizontalSpeed)
{
transform.localScale = new Vector2 (Mathf.Sign(myRigidbody.velocity.x), 1f);
}
}
}
Edit: Updated to include all class code.
Thanks