Cannot convert from float to UnityEngine.Vector2

This is my code:

public class PlayerMovement : MonoBehaviour {
public Rigidbody2D rb;
public float SidewaysForce = 500f;
public float UpwardsForce = 500f;
void FixedUpdate()
{
if (Input.GetKey(“d”))
{
rb.AddForce(SidewaysForce * Time.deltaTime, 0f);
}
if (Input.GetKey(“a”) )
{
rb.AddForce(-SidewaysForce * Time.deltaTime, 0f);
}
if (Input.GetKey(“w”) )
{
rb.AddForce(0f, UpwardsForce * Time.deltaTime);
}
}
}
And I get these errors:

Error CS1503 Argument 1: cannot convert from ‘float’ to ‘UnityEngine.Vector2’ New Unity
Error CS1503 Argument 1: cannot convert from ‘float’ to ‘UnityEngine.Vector2’ New Unity
Error CS1503 Argument 1: cannot convert from ‘float’ to ‘UnityEngine.Vector2’ New Unity
Error CS1503 Argument 2: cannot convert from ‘float’ to ‘UnityEngine.ForceMode2D’ New Unity

Had to translate the errors into english, I’m sorry if they aren’t translated correctly!
Hope you can tell me what is wrong…

Read the error… cannot convert from float to Vector2.

What do you think that means?

Note, SidewaysForce and UpwardsForce are both float, and AddForce expects a Vector2.

Please take a look at the docs and you will see that there is no overload that matches the signature you’re looking for.
You’re passing a couple of floats from what I can see. Instead, if you’re aiming to apply the force in a relative direction you could do the following for example,

 rb.AddForce(transform.forward * forwardsForce);

As the docs show, you can either pass a Vector and a forcemode, or 3 floats (which is essentially the same as the vector) and a forcemode.

1 Like

Seach on youtube So many videos on 2d character movement.