Hello,
I am working on a 3d game right now and I have been trying out moving a gameobject with a joystick. So far I have been able to get the gameobject to move along the x-axis in both positive and negative directions. But the issue that I am running into now is I want the gameobject to stop moving after it reaches a certain distance along the x-axis in both positive and negative directions. Currently what is happening is the gameobject is allowed to move either left or right forever and there is no restriction. I am wondering if anybody has any suggestions for how I can add the restriction.
Here is the code that I have that moves the player along the x-axis with the joystick
private void FixedUpdate()
{
if (gm.joystick.Horizontal >= .1f)
{
transform.Translate(Vector3.right * Time.deltaTime * runSpeed);
}
else if (gm.joystick.Horizontal <= -.1f)
{
transform.Translate(Vector3.left * Time.deltaTime * runSpeed);
}
}
I am also moving the player forward forever and when the gameobject reaches that point on the x-axsis I dont want the gameobject to stop moving forward. Here is the code for moving the gameobject forward
if (isJumping == false)
{
rb.AddForce(Vector3.forward * Time.deltaTime * forceMulti);
}
the jumping bool is there for when the game pauses and nothing else.
If anybody has any suggestions for what I could do that would be great!
Thanks!