Compile Error: Cannot implicitly convert type (float, float) to Vector2

Hey I’ve been running into this problem while trying to do some physics in Unity. So i made everything floats (as you’ll see in the code below) by casting it as one and storing it in float variables so idk what’s going on. Please help.

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

public class IDK : MonoBehaviour
{
    private Vector2 bossV;
    private Vector2 bossJump;
    private float initialV, jumpAngle, jumpAngleA, jumpAngleB, jumpAngleC;
    public float jumpTime;
    public Rigidbody2D rb;
    private double bossVX, bossVY;

    void JumpAttack()
    {
        bossV = this.transform.position;
        jumpAngleA = (float)(0.5 * 4.0 * -9.8 * System.Math.Pow(bossV.x / initialV, 2));
        Debug.LogFormat("jumpAngleA = {0}", jumpAngleA);
        jumpAngleB = (bossV.x);
        jumpAngleC = (float)(-1.0 * bossV.y + 0.5 * 4.0 * -9.8 * System.Math.Pow(bossV.x / initialV, 2));
        jumpAngle = (float)(System.Math.Atan((-1.0 * jumpAngleB + System.Math.Sqrt(System.Math.Pow(jumpAngleB, 2) - 4.0 * jumpAngleA * jumpAngleC)) / 2.0 * jumpAngleA));
        bossVX = (-1f * initialV * System.Math.Cos(jumpAngle) * jumpTime + bossV.x);
        bossVY = (-0.5f * 4f * -9.8f * jumpTime * jumpTime + initialV * System.Math.Sin(jumpAngle) * jumpTime);
        bossV = (System.Convert.ToSingle(bossVX), System.Convert.ToSingle(bossVY));
    }
}

You’re using tuples when the error is saying a Vector2 is required. You can just new() a Vector2 rather than using tuples.

1 Like

omg it was so simple. thank you so much!

1 Like