Hello! I’m quite new to Unity and trying to use mathf.smoothdamp
I have a main menu camera that moves when moving the mouse over the screen for some added flare. I got that to work, however I thought it would look better if the motion was smooth. That’s what I’m having a problem with.
When I hit play, the camera is static and not moving with the new smoothing script.
I did not forget to set the public floats to numbers other than zero.
I did that before posting to the discussion forum.
using UnityEngine;
public class MenuCam : MonoBehaviour
{
public float sensX;
public float sensY;
public float smoothspeed;
//Folosit yRot in loc de yRotation pentru ca alt script foloseste yRotation si nu ma deranjeaza destul cat sa repar
float yRot;
float xRotation;
float smoothposX;
float smoothposY;
public float velositiX;
public float velositiY;
private void Update()
{
float mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX;
float mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY;
float smoothposX = Mathf.SmoothDamp(yRot, mouseX, ref velositiX, smoothspeed * Time.deltaTime);
float smoothposY = Mathf.SmoothDamp(xRotation, mouseY, ref velositiY, smoothspeed * Time.deltaTime);
//De ce cacat e "+="
yRot += smoothposY;
xRotation -= smoothposX;
//Blocheaza miscarea ca sa nu vada camera OOB
xRotation = Mathf.Clamp(xRotation, 13.5f, 16f);
yRot = Mathf.Clamp(yRot, 140f, 142.5f);
transform.rotation = Quaternion.Euler(xRotation, yRot, 0);
}
}
I apologise if this is a trivial issue, I’m not only a beginner to Unity, but also programming as a whole.
P.S. You can ignore the comments, they are unrelated to the issue. They don’t really describe anything useful.