So appearently after typing the clamped code my ships position from the camera completely changes when i hit play. im not sure if it has anything to do with that my ships starting position is -72. its not really something ican change but im guessing thats the reason and it has to range between -62 and -82 but im not too sure i thought doing 10 would work but it would just snap it to 10 instead of clamping it
MY CODE;
…
[SerializeField] float xRange = 5f;
[Tooltip("In ms per second")][SerializeField] float xSpeed = 4f;
void Start()
{
}
void Update()
{
float xThrow = CrossPlatformInputManager.GetAxis("Horizontal");
float xOffset = xSpeed * xThrow * Time.deltaTime;
float rawXPos = transform.localPosition.x + xOffset;
float xClamped = Mathf.Clamp(rawXPos, -xRange, xRange);
transform.localPosition = new Vector3(xClamped, transform.localPosition.y, transform.localPosition.z);
}
}
…
Edit: alright so i found the root of the problem but i dont understand why. So when i put in the xClamped variable into the new Vector3 thats when my ships entire x positio changes from its path but i dont understand why i just know thats why.