- Home /
how do i smooth between 2 clamps
need to smooth from one clamp to another so the first person cam movement isnt jerky when my player is sliding. have no idea how to do it. heres my code
if (player.move_forward == true)
{
yaw += speedH * Input.GetAxis("Mouse X");
pitch -= speedV * Input.GetAxis("Mouse Y");
if (player.is_sliding == true)
{
pitch = Mathf.Clamp(pitch, slidingPitchMinMax.x, slidingPitchMinMax.y);
yaw = Mathf.Clamp(yaw, yawMinMax.x, yawMinMax.y);
}
else
{
pitch = Mathf.Clamp(pitch, pitchMinMax.x, pitchMinMax.y);
yaw = Mathf.Clamp(yaw, yawMinMax.x, yawMinMax.y);
}
transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
}
I'm not sure what you're trying to do, maybe $$anonymous$$athf.SmoothDamp is what you're looking for
i have more of a restriction on the pitch clamp when sliding so you cannot look down as much. so if you are looking down when the character starts sliding the camera will snap to the allowed pitch. instead I want it to smooth there
Answer by Magso · Sep 18, 2020 at 11:50 PM
You need to lerp another float value to pitch
and set transform.eulerAngles.x
to that lerped value like this.
lerpedPitch = Mathf.Lerp(lerpedPitch, pitch, Time.deltaTime);
transform.eulerAngles = new Vector3(lerpedPitch, yaw, 0.0f);
Make sure lerpedPitch
is declared in the class at the top and not in the function.
Thanks for your help. I tried this with now success but I'm sure I implemented your suggestion wrong. public float speedH = 2.0f; public float speedV = 2.0f;
private float yaw = 0.0f;
private float pitch = 0.0f;
public Vector2 yaw$$anonymous$$in$$anonymous$$ax = new Vector2 (-165, 165);
public Vector2 pitch$$anonymous$$in$$anonymous$$ax = new Vector2 (-85, 35);
public Vector2 slidingPitch$$anonymous$$in$$anonymous$$ax = new Vector2 (-85, -15);
public float lerpedPitch;
void Update()
{
if (player.move_forward == true)
{
yaw += speedH * Input.GetAxis("$$anonymous$$ouse X");
pitch -= speedV * Input.GetAxis("$$anonymous$$ouse Y");
if (player.is_sliding == true)
{
lerpedPitch = $$anonymous$$athf.Lerp(lerpedPitch, pitch, Time.deltaTime);
transform.eulerAngles = new Vector3(lerpedPitch, yaw, 0.0f);
pitch = $$anonymous$$athf.Clamp(pitch, slidingPitch$$anonymous$$in$$anonymous$$ax.x, slidingPitch$$anonymous$$in$$anonymous$$ax.y);
yaw = $$anonymous$$athf.Clamp(yaw, yaw$$anonymous$$in$$anonymous$$ax.x, yaw$$anonymous$$in$$anonymous$$ax.y);
}
else
{
pitch = $$anonymous$$athf.Clamp(pitch, pitch$$anonymous$$in$$anonymous$$ax.x, pitch$$anonymous$$in$$anonymous$$ax.y);
yaw = $$anonymous$$athf.Clamp(yaw, yaw$$anonymous$$in$$anonymous$$ax.x, yaw$$anonymous$$in$$anonymous$$ax.y);
}
transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
}
}
The two lines under if (player.is_sliding == true)
need to be at the bottom replacing transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
I see, I tried that but it lerps the mouse position at all times not just at the start of the slide. None the less - thank you for your effort. I am going with a different approach now.
Your answer
![](https://koobas.hobune.stream/wayback/20220613012123im_/https://answers.unity.com/themes/thub/images/avi.jpg)