Answer the question
In order to leave comments, you need to log in
How to soften camera movement?
When moving the camera using Touch, it does not move smoothly.
private Touch touch;
public float speed = 0.01f;
//public float speedFinal = 60f;
public GameObject mainScriptObject;
private MainScript mainScript;
void Start()
{
mainScript = mainScriptObject.GetComponent<MainScript>();
}
void Update()
{
if (Input.touchCount > 0 && !mainScript.isFreezed)
{
touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Moved)
{
transform.position = new Vector3(
Mathf.Clamp(transform.position.x - touch.deltaPosition.x * speed, -100.0f, 100.0f),
transform.position.y,
Mathf.Clamp(transform.position.z - touch.deltaPosition.y * speed, -100.0f, 100.0f));
}
}
}
Answer the question
In order to leave comments, you need to log in
if (touch.phase == TouchPhase.Moved)
{
const float SMOOTH = 0.1f;
var newPos = new Vector3(
Mathf.Clamp(transform.position.x - touch.deltaPosition.x * speed, -100.0f, 100.0f),
transform.position.y,
Mathf.Clamp(transform.position.z - touch.deltaPosition.y * speed, -100.0f, 100.0f));
transform.position = Vector3.Lerp(transform.position, newPos, SMOOTH);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question