- Home /
Looking to see if the method I'm using for movement is correct or if I'm doing something wrong.
Let me start out by saying that this all works and I'm happy with the outcome. However, I'm wondering if I'm using everything correctly. Here is my move function. I'm grabbing the mouse position and changing it into a world point. Then using the Vector2.Lerp function. I run PlayerMove() in the update method and then I run a rb.MovePosition(new Vector2(0f, shuttlePosition.y)) under FixedUpdate.
What I'm not confident about is using "new Vector2" in the rb.MovePosition. I know new is creating a reference of the new vector2 and I feel like this isn't the correct way to do this. Maybe I'm missing some understanding on the new keyword but from my knowledge is that it's allocating memory for the reference vector2 and I suspect that I shouldn't being doing a new reference everytime I want to move.
private void PlayMove()
{
if (isDead == false)
{
mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
shuttlePosition = Vector2.Lerp(transform.position, mousePosition, shuttleSpeed * Time.deltaTime);
}
}