I am kinda new to programming, and was following a yt tutorial for 2d movement in Unity. But it returns this error. I am not sure what’s wrong. I am kind of especially lost when it comes to Vectors, so any insight would be great lol. Thanks in advance
public class NewBehaviourScript : MonoBehaviour
{
public float moveSpeed;
public Rigidbody2D rb;
private Vector2 moveDirection;
// Update is called once per frame
void Update()
{
ProcessInputs();
}
void FixedUpdate()
{
Move();
}
void ProcessInputs()
{
float moveX = Input.GetAxisRaw("Horizontal");
float moveY = Input.GetAxisRaw("Vertical");
moveDirection = new Vector2(moveX, moveY).normalized;
}
void Move()
{
rb.velocity = new Vector2(moveDirection * moveSpeed, moveDirection.Y * moveSpeed);
}
}
Move() is where I get the error message, “error CS1503: Argument 1: cannot convert from ‘UnityEngine.Vector2’ to ‘float'”
New contributor
haley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.