Lerp to a fixed distance
Hey everyone ! Being quite bad in Maths, I would need some assistance !
I'm making a chess-like game and I want as move animation a Lerp from start Pos to end Pos, but making the chess piece "teleport" when it goes away from it's starting tile to get to it's destination tile. That way, I want the animation to last as long if I move by one unit or at the edge of the terrain.
Is there any way to find the vector3 at a fixed distance in a given axis ? I would so be able to make two Lerps, one from the center of my starting pos to it's edge (in the direction of my destination) and the second one from the edge of my destination pos to it's center.
currentposition + Vector3.forward*dist;
thats the position in distance units in the forward direction from your current position!
Thanks Scribe! I guess I have to change Vector3.forward by a vector pointing to my destination position. So it would be currentPosition + (destinationPosition-currentPosition)*distance
? I'll test this !
The direction vector must be normalized! Or the point wont be scaled right.
@DevPoG if you already have the destination point you can just do $$anonymous$$athf.Lerp(currentPosition, destinationPosition, t);
for a varying t.
$$anonymous$$aybe you could explain this sentence more: "I want as move animation a Lerp from start Pos to end Pos, but making the chess piece "teleport" when it goes away from it's starting tile to get to it's destination tile."
As $$anonymous$$ikilo said, I should have mentioned, you need to normalise the direction vector:
currentPosition + someDirection.normalized*dist;
$$anonymous$$y bad, forgot about the normalized function ! And I would want the same visual effect as a Lerp, but having the chess piece only display in the starting tile and destination tile, not every tile that may be in between :)
By calculating the point at distance X from the start, I will be able to make a first Lerp, then teleport the player to the destination and do the same (in a reversed way) !