I know there are similar questions to this and I have probably read them. The issue is that nothing I’ve tried seems to work. I currently am just trying to do a simple movement of a cube around a open plane using touch features. I have the touch controls working and the cube does move. However, it instantaneously moves and rotates to its new position. I want it to accelerate towards the target point and then slow as it approaches it. I have been told that Lerp could be used but adding it in to the program didn’t seem to accomplish anything. (Sorry for the unorganized question, I have a horrible time communicating problems). My code is below. I know its unorganized and probably inefficient but I’m not trying to do anything groundbreaking as I am still learning all the ins and outs of Unity. Not looking for someone to do the code for me, just looking for a push in the right direction would be great thanks.
var touch : Touch;
if (Input.touchCount > 0) {
if (Input.GetTouch(0).phase == TouchPhase.Moved){
var primarytouch : Touch = Input.GetTouch(0);
var speed = primarytouch.deltaPosition/primarytouch.deltaTime;
}
if (Input.GetTouch(0).phase == TouchPhase.Ended){
var finishedtouch : Touch = Input.GetTouch(0);
var ray : Ray = Camera.main.ScreenPointToRay(finishedtouch.position);
var controller : CharacterController = GetComponent(CharacterController);
var hit : RaycastHit;
var moveDirection : Vector3 = Vector3.zero;
if (Physics.Raycast(ray,hit,100))
{
var startPos = transform.position;
var targetPoint = hit.point;
var targetRotation = Quaternion.LookRotation(targetPoint - transform.position, Vector3.up);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.time *2.0);
transform.position = Vector3.Lerp(startPos, hit.point, Time.time * 10);
}
}
}
}