Rigidbody 2D not accepting any value types (byte to double)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMove : MonoBehaviour
{
    private PlayerInput playerInput;
    private PlayerInput.OnFootActions onFoot;
    private Vector2 input;
    private Vector3 Direction;
    public float speed = 5.0f;
    public bool isGrounded;
    public float jumpHeight;
    private Rigidbody2D rb;
    // Start is called before the first frame update
    void Awake()
    {
        playerInput = new PlayerInput();
        onFoot = playerInput.OnFoot;
        rb = GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    public void OnTriggerEnter(Collider other)
    {
        isGrounded = true;
    }
    public void OnTriggerExit(Collider other)
    {
        isGrounded = false;
    }
    public void Jump ()
    {
    if(isGrounded == true)
        {
// CS0029 occurs here.
// Tried byte, short, int, long, float, and double and none work.
            rb.velocity = (0, 1);
        }
    }
    void Update()
    {
        onFoot.Enable();
    Direction.x = input.x;
        input = (onFoot.Movement.ReadValue<Vector2>());
        transform.position += (Direction * speed * Time.deltaTime);
    }
}

Error: CS0029

Why does it not accept any value types? Even in regular rigidbody, still…
If you know the fix, please tell me.

By the way, the PlayerInput is a reference to the action maps I have.
Thanks in advance.

Nobody memorizes what “CS0029” means. If you’re going to productively post a problem on the forum, you need to copy/paste the whole thing. It tells you what the error is, and what line is most likely the problem, crucial information for debugging it.

Just by looking through it though, the most obvious culprit is line 36, rb.velocity = (0, 1); You need to set the velocity to a Vector2, like it does in the documentation.

2 Likes

rb.velocity = (0, 1); isn’t valid syntax. You should refamiliarise yourself on how to declare new instances of classes and structs.

1 Like

Unfortunately with newer C# versions it’s actually valid syntax (see tuple), but still wrong. That’s why the errors become more cryptic. In the past the compiler would have complained about the syntax, now it just complains about a type mismatch as a tuple (int, int) is not the same as a Vector2 struct.

It’s also nothing to do with a Rigidbody, you’re talking about a standard C# property. This property could be on anything. As above, it wants a Vector2 so you have to assign a Vector2.

Also, it seems you have bigger issues if you’re using 2D physics and are expecting it to call the 3D physics callbacks such as “OnTriggerEnter” and “OnTriggerExit”. You’d need to use “OnTriggerEnter2D” and “OnTriggerExit2D” which return a “Collider2D” not a “Collider” (3D).

2 Likes