- Home /
Question by
Joy-Kumar · Jan 31, 2017 at 10:01 AM ·
vector3lerpmovement scripttransform.translate
Smooth touch for map
I have to make the 3Dmap motion somewhat free and smooth like we get in lerp. I donno how to apply in it, Please help me out...
i need free movement like hills of glory 3D game ..
using UnityEngine; using System.Collections;
public class PanCamera : MonoBehaviour {
public float speed = 0.1f;
public float MIN_X = 7f;
public float MAX_X = 12f;
public float MIN_Y = 8f;
public float MAX_Y = 13f;
public float MIN_Z = 10f;
public float MAX_Z = 10f;
public Vector3 nextPosition;
public float moveSpeed;
public int camAdjust = 10;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.touchCount == 1 && Input.GetTouch (0).phase == TouchPhase.Moved) {
Vector3 touchdeltaPosition = Input.GetTouch (0).deltaPosition;
transform.Translate (-touchdeltaPosition.x * speed*Time.deltaTime, -touchdeltaPosition.y * speed*Time.deltaTime, 0);
transform.position.y = Terrain.activeTerrain.SampleHeight(transform.position) + camAdjust;
transform.position = new Vector3(
Mathf.Clamp(transform.position.x, MIN_X, MAX_X),
Mathf.Clamp(transform.position.y, MIN_Y, MAX_Y),
Mathf.Clamp(transform.position.z, MIN_Z, MAX_Z));
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Smooth movement using transform.Translate 2 Answers
Vector3.Lerp - Constant speed between distance changes 3 Answers
Collision.contacts? 1 Answer
Stop a Lerp from looping 3 Answers
How to Gradually Increase Speed with Lerp or Slerp? 1 Answer