Why am I getting this CS0019 error?
I'm trying top make a 2D top down game with a boat. I have gotten the boat to move up, down, left, and right when using the arrow keys. I also want the boat to rotate when there's input so that it looks like the boat is slowly drifting left and right. Here's my script:
public class PlayerMovement : MonoBehaviour
{
//boats movement speed and drift speed.
private float moveSpeed = 2f;
private float driftSpeed = 3f;
//This moves the boat.
public Rigidbody2D rb;
Vector2 movement;
Vector2 rotation;
//Player input.
void Update()
{
//Return value of horizontal axis between -1 to 1 and sets it to the x position.
movement.x = Input.GetAxisRaw("Horizontal");
//Return value of vertical axis between -1 to 1 and sets it to the y position.
movement.y = Input.GetAxisRaw("Vertical");
//Return value of horizontal axis between -1 to 1 and sets it to y rotation.
rotation.x = Input.GetAxis("Horizontal");
}
//Movement of boat.
void FixedUpdate()
{
rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
rb.MoveRotation(rb.rotation + rotation * driftSpeed * Time.fixedDeltaTime);
}
}
So the movement is fine. But that last line "rb.MoveRotation" is getting an error. This is the error:
CS0019 Operator '+' cannot be applied to operands of type 'float' and 'Vector2'
I'm confused because I don't understand why "rb.position + movement" was okay, but "rb.rotation + rotation" wasn't. Sorry if this is a dumb question I'm just starting out and trying to practice on my own during my free time.