Object follow cursor using plane due to perspective cam?

Hello there,

I’m using this simple code:

var yourCube : Transform;
var Timer = 0.0;
var height = 0;


function Update () {

var ray =Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;

   if(Physics.Raycast(ray,hit)){
      yourCube.position = Vector3(hit.point.x,height,hit.point.z);
}
     
 }

This works really fine for Orthographic cam but now I need to use Perspective. Can anyone please guide me on how to create a plane to end with the follow up delay?

Thanks in advance

create a plane to end with the follow
up dela

I don’t know what this means. This code will largely work for a perspective camera. If the camera is angled, you might want to change line 11 to:

 yourCube.position = hit.point + hit.normal * height;

Just solved my problem using Culling Mask.