- Home /
object follow mouse on x-z plane with angled camera
hi,
i have 3 cameras placed on the scene and user can switch between them. in each of cameras user can drag a wall and place it somewhere that he/she wants.
now the problem is i want the object (wall) to follow mouse on the x-z plane meaning that the transform.z of wall should always be 2f.
the problem is my code works fine on the top camera (all are perspective cameras) but if i switch to other 2 angled cameras, it does not work correctly. these are the position of my cameras :
and this is the code for dragging :
Vector3 pos = Input.mousePosition;
Vector3 targetPos = new Vector3 (pos.x, pos.y,gc.activeCam.transform.position.z);
Vector3 worldPos = gc.activeCam.ScreenToWorldPoint (targetPos);
worldPos.y = 2f;
print(worldPos);
transform.position = Vector3.MoveTowards (transform.position, worldPos, 15f * Time.deltaTime);
(i run this code on update so i use MoveTowards)
what is wrong with my code ?
screen-shot-1395-10-23-at-32724-pm.png
(256.2 kB)
Comment
Your answer

Follow this Question
Related Questions
Top-Down Camera Trouble 1 Answer
Camera not moving on mobile 0 Answers
How to make your character move? 7 Answers
Camera Border Follow 1 Answer