I Don't Know How To Use Raycast?

Hi, I’m trying to make a 2D game in which the player jumps from falling platform to falling platform. in order to make the jump, i’m trying to have it so that when you click on the screen, it will use the players position and the mouses position in order to create a ray, and then move the player(with the Ignore Raycast tag) to whatever collider collides with the ray.

When testing i found that the ray refuses to take the player to a negative coordinate, and even if i try to take it into the positive coordinates, the coordinates will be slightly higher than they should.

here’s my code

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

public class Player_Move : MonoBehaviour {


    private Collider2D Move_Target;


    private string Platform_Tag;

    private Rigidbody2D rb;

    private Vector2 Mouse_Pos;

    private RaycastHit2D Move_Ray;

    void Move()
    {
        Mouse_Pos = Input.mousePosition;

        Debug.Log(Mouse_Pos);

        Move_Ray = Physics2D.Raycast(transform.position, Mouse_Pos);



        Move_Target = Move_Ray.collider;

        Debug.Log(Move_Target);

        transform.position = Move_Ray.point;



    }
   

    // Use this for initialization
    void Start () {
        rb = GetComponent<Rigidbody2D>();
    }
   
    // Update is called once per frame
    void Update () {


        if (Input.GetButtonDown("Jump"))
        {
            Move();
        }
    }
}

Input.mousePosition is in screen space. Objects in the world are in world space. You need to convert screen space to world space in order to use it with Raycast.

You can do this using methods on the camera, such as the ScreenToWorldPoint method.

Thanks you so much

now I just have to find out how to change the object it landed on’s tag to Ignore Raycast as well.

transform.parent = Move_Target.transform;

transform.parent.tag = "Ignore Raycast"; // <- "tag.Ignore Raycast is not defined." it should be defined by default

Edit: Nvm It’s supposed to be a layer, i’m retarded.