Hello Is it Possible to Clamp “X” axis movement Position on These Codes? Or Can we add something else?
It is just a platform and Player moves on the Z axis.
Void Update()
{
MoveVector = Vector3.zero;
//Touch Horizontal difference will be change the _horizontal value;
if (Input.touchCount > 0)
{
touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Moved)
{
Pos = transform.position;
MoveVector.x = (Pos.x + touch.deltaPosition.x) * moveSideDelta;
if (touch.deltaPosition.x > touchDistanceDeltaToFace || touch.deltaPosition.x < -touchDistanceDeltaToFace)
{
Vector3 face = controller.velocity;
face.y = 0;
transform.forward = (Vector3.Lerp(transform.forward, face, Turn_speed));
}
}
if ((touch.phase == TouchPhase.Ended))
{
transform.forward = Vector3.forward;
}
}
MoveVector.x = Mathf.Clamp(MoveVector.x, -3f, 3f);//I think This Clamps The Amount Of Moving Distance to Left and Right at a time.
MoveVector.z = PlayerSpeed;
controller.Move(MoveVector * Time.deltaTime);
}