I have a character with a Rigidbody2D that I move by adding or subtracting from it’s velocity in the x direction. I have 2 buttons, one moves the character left (subtracting from velocity.x) and one that moves the character right (adding to velocity.x).
This works great in editor using the buttons, but on device the velocity never gets high enough for the character to move significantly. The character ends up moving super super slow. It seems like the Update loop for the button on device runs slower than it does in editor. Any ideas why?
I have the buttons set up so you can tap and hold them to continue moving the character. They are set up like this:
public class LeftButton : Button
{
public static System.Action SendLeft;
void Update()
{
if (IsPressed())
{
if (SendLeft != null)
SendLeft();
}
}
}
And then in my character class, I have the detection set up like this:
void Start()
{
LeftButton.SendLeft += MoveLeft;
}
void MoveLeft()
{
float newXVelocity = Rigidbody2D.velocity.x - 0.1f;
if (newXVelocity < -MAX_VELOCITY)
newXVelocity = -MAX_VELOCITY;
Rigidbody2D.velocity = new Vector2(newXVelocity, Rigidbody2D.velocity.y);
}