- Home /
Vector3.lerp between two points, one point being player controlled?
I'm making a slingshot-style game with the player able to aim a slingshot by touching the screen. When they touch the screen, the projectile begins a Vector3.lerp between its original stationary position and the point of the screen they've touched via screenpointtoworld. The problem occurs when the player moves their finger/input point, the lerp causes the projectile to 'lag' in its course. I want the lerp between its original position and the input point to be slow-ish to insinuate tension, but the actual destination orientation to be 1:1. Speeding up the lerp speed accomplishes this, but I lose the sense of tension then because it reaches the player input point quickly. I've drawn some diagrams just in case I'm not clear enough;
Diagram 1: Point C is where the projectile originates, and point A is the players touch input. If the player drags their touch input to point B, the projectiles path to B lags due to the current lerp speed, which needs to be slow to create the idea of tension.
Diagram 2: This is what I want to achieve. Even though the players input has moved, the projectiles course stays accurate to the input but the speed at which it gets there is slow.
The code on the projectile currently looks like this:
if (Input.GetMouseButton (0) && InFlight == false) {
Pullback = MainCam.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x, Input.mousePosition.y, MainCam.nearClipPlane+1));
//Ignore the nearClipPlane part, its part of something, and I'm using mousePosition during development
transform.position = Vector3.lerp(transform.position,Pullback,Time.deltaTime);
}
Perhaps Vector3.lerp isn't the right function for this idea?