I'm trying to convert this code that emits a RayCast3D from Camera3D into 2D:

func _process(delta):
	var mouse_position: Vector2 = get_viewport().get_mouse_position()
	ray_cast_3d.target_position = project_local_ray_normal(mouse_position) * 100.0   <<- Error!
	ray_cast_3d.force_raycast_update() 

	if ray_cast_3d.is_colliding():
		var collider = ray_cast_3d.get_collider()
		print(collider)

I'm getting an error that project_local_ray_normal is not a part of Camera2D class. I looked at the docs. for Camera2D but couldn't figure out the alternative. What should I do here?

  • xyz replied to this.

    Abdo_23 What would be the point of casting a ray from a 2d camera?

      xyz
      Clicking on different nodes including individual Tiles inside a TileMap

      • xyz replied to this.
        • Edited

        Abdo_23 Just call get_global_mouse_position() and you'll get the position of the mouse in 2D world.