Hi lovely unity guys again,
I need some help with easing character controller movement. I’m developing an iPad app with a character moving with a finger swipe. Basically, it moves when i wipe my finger across the screen. How do I achieve an easing movement before the character eventually comes to a stop. I’ve stripped down some of the codes but the character movement is something like this.
private var character : CharacterController;
var movement : Vector3 = Vector3.zero;
movement = thisTransform.position - targetLocation;
movement *= Time.deltaTime;
character.Move( movement );
I reckon there should be some of a smoothing script? please correct me if i’m wrong.
Thanks guys. Appreciate it.
Rgds,
jser
updated code:
var startspot : Transform;
var endspot : Transform;
function Start () {
SmoothMove(startspot.position, endspot.position, 5.0);
}
function SmoothMove (startpos : Vector3, endpos : Vector3, seconds : float) {
var t = 0.0;
while (t <= 1.0) {
t += Time.deltaTime/seconds;
transform.position = Vector3.Lerp(startpos,
endpos, Mathf.SmoothStep(0.0, 1.0, t));
yield;
}
}