Question by
HizrokGames · Jul 01, 2017 at 09:09 PM ·
movementplayer movement
Moving player with mouse problem Vector3.MoveTowards()
Hello, I have an issue with Vector3.MoveTowards(). I have a game where I am moving the player with mouse and I want to make it smooth, so I added a Vector3.MoveTowards() function:
public class PlayerController : MonoBehaviour {
public float depth = 5.0f;
public float speed = 10f;
private void Update()
{
float speedWithTime = speed * Time.deltaTime;
Vector3 mousePos = Input.mousePosition;
Vector3 wantedPos = Camera.main.ScreenToWorldPoint(new Vector3(mousePos.x, mousePos.y, depth));
transform.position = Vector3.MoveTowards(transform.position, wantedPos, speedWithTime);
}
}
I cant move the player now. What is the problem?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612125047im_/https://answers.unity.com/themes/thub/images/avi.jpg)