I want to restrict a ball’s position to the viewport of the camera so it doesnt go out of the view port.
I wasnt able to find the solution any where, however I found it on unity forum
which was like this,
- void Update() {
-
Vector3 pos = Camera.main.WorldToViewportPoint (transform.position);`
-
pos.x = Mathf.Clamp01(pos.x);`
-
pos.y = Mathf.Clamp01(pos.y);`
-
transform.position = Camera.main.ViewportToWorldPoint(pos);`
-
}
As you can see in line number 2 I use the WorldToViewPort and the transform is of the the object. Remember this is in Unity.
Now I am trying to implement this exact same functionality here in playcanvas.
The project is this:
Controls: Pan left,right,up or down to control the ball
Any help would be appreciated.