Ship is fixed to x (if not fixed moving to the x positive very fast)

float xThrow = CrossPlatformInputManager.GetAxis(“Horizontal”)float xOffset = xThrow * xSpeed * Time.deltaTime;
float xRaw = transform.position.x + xOffset;
float xfSpeed = Mathf.Clamp(xRaw, -32, 28);
transform.localPosition = new Vector3(xfSpeed, transform.localPosition.y, transform.localPosition.z);

So this is my code, if i remove the math.clamp, the ship will go indefinitely to the x positive side, and if use clamp is just fixed to the limit of x assigned. I printed all the values and the xThrow is working just find, no key imput that i havent noticed. So i wanted to know what is going on, those are the only lines of code that my scrip have.

Hi Euclides,

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture? And have you already rewatched the video at least one more time? If so, how did you come up with the values -32 and 28?

Thank you, i just copied and pasted the code in the lecture project changes and it works perfectly

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms