How can i convert screen point to world point
I have set a orthographic size for my camera . And i take in touch position from the user , Like this.
RaycastHit2D hitInfo = Physics2D.Raycast (Camera.main.ScreenToWorldPoint (touchPosition), Vector2.zero); I can get other touch positions like this Debug.Log (touchPosition); This would give me the pixel value i guess . But i want to convert it to the range of 0,1 ,the zero at screen bottom and 1 at screen top.
so that i can later convert it into some position in grid layout cell . Here is the transformation i'm using for that
float maxX = Camera.main.gameObject.transform.GetComponent<gridadjustment> ().cellWidth / 2;
float minX = -(Camera.main.gameObject.transform.GetComponent<gridadjustment> ().cellWidth / 2);
float maxY = Camera.main.gameObject.transform.GetComponent<gridadjustment> ().cellHeight / 2;
float minY = -(Camera.main.gameObject.transform.GetComponent<gridadjustment> ().cellHeight / 2);
float scaleFactorX = touchPosition.x * (Math.Abs (maxX - minX))-minX;
float scaleFactorY = touchPosition..y * (Math.Abs (maxY - minY))- minY;
Here touch position is the value saved in this way( Camera.main.ScreenToWorldPoint (touchPosition))
and than i'm gonna use this scaleFactor to scale the game object locally inside the cell.
I can use this scaleFactorX and scaleFactorY if i had the touchPosition.x and touchPosition.y in the range of 0 to 1.
Answer by Brijs · Jun 16, 2016 at 10:13 AM
Use Camera.ScreenToViewportPoint() method to convert screen points to range of 0-1
Well that alone didn't helped me completely for what i was looking for , but it came as an aid . Thank You , very much.
Your answer
Follow this Question
Related Questions
can i create a grid, using the screen size? 2 Answers
Creating a Grid using an Array with C# 1 Answer
Keeping track of a bunch of objects in a 3D grid 0 Answers
Why do I get a vertical grid in a new scene? 7 Answers
Hexagon grid check for specific tile 0 Answers