- Home /
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
Answer by robertbu · Jul 18, 2014 at 03:34 AM
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;
Thanks.
This solves part of the problem. The cube now follows the cursor the way I wanted but the problem is that it starts rising. Hit point is hiting all the heigh values I guess.
Is there a way to raycastHit only in the desired plane?
You an ray cast agains a specific object using Collider.Raycast(). There is only one form of this kind of Raycast, so you will have to specific a distance as the third parameter. You will need to add some sort of reference to the collider of the plane to be used in this code.
So what I need is to maintain the perspective cam on the bottom and, somehow, control the figure and the obeject using a orthographic cam. Any scripts? thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220613154350im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Generate a plane and change it's UV's to give perspective 0 Answers
Math - calculate position in world space from ray on infinite plane 2 Answers
How do I use Material/Texture alpha on a plane? 2 Answers
Make an instantiated plane face the camera at all times 3 Answers
2d plane falls through and half disapears when on terrain 0 Answers