So, I am making a 2d board game with unity. Basically, two characters are moving on the board when clicking a spot on the board. Since it's a static one frame 2d game, I put all of my game objects children of the canvas. All the positions seems to be aligned, in the canvas itself everything is in place, also when I am debugging I notice that both of the positions, the local position and the target position are correct, so when I'm not using lerp and just setting the character position to the target position, it works perfect.
Lerp/Smooth damp are working perfect outside the canvas I think it's something related to the update function, as it's updating false positions, but that's all I can guess... This is the Update function of the Player class:
private void FixedUpdate()
{
if (moveTowards == true)
{
velocity = Vector3.zero;
this.transform.position = Vector3.SmoothDamp(this.transform.localPosition, targetSpotPosition, ref velocity, .08f);
}
if (this.transform.position == targetSpotPosition)
{
moveTowards = false;
}
}
moveTowards set to true when clicking a spot.
public void movePlayerTo(Spots moveHere)
{
moveTowards = true;
moveHere.transform.position = Camera.main.ScreenToWorldPoint(moveHere.transform.position);
targetSpotPosition = moveHere.transform.position;
//targetSpotPosition = Camera.main.ScreenToWorldPoint(targetSpotPosition);
}
moveHere is the spot's position, there's no problem there.
I set my canvas to camera space render mode, and of course scale with screen size. Before putting everything in the canvas, it worked perfectley.
HELP PLEASE. Thanks in advance,
Omer