- Home /
Camera not being moved when dragged by mouse
Hey all, I am having a conundrum that I can't seem to figure out, and I have tried several solutions.
I have two camera's. The main camera and another camera that just renders GameObjects in front of it.
So when a player clicks on a gameobject, the game will create a prefab in front of the second camera and let's players rotate it.
I'm trying to code it so players and click and drag the mouse to simulate moving the item around but moving the camera, (it seemed easier then trying to find the offset of a raycast point and everything)
Here is the code as follows :
public void MoveCamera()
{
if (Input.GetMouseButtonDown(1))
{
origin = investigateCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,
Input.mousePosition.y, investigateCamera.nearClipPlane));
if (Input.GetMouseButton(1))
{
difference = origin - investigateCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,
Input.mousePosition.y, investigateCamera.nearClipPlane));
investigateCamera.transform.position = new Vector3(difference.x, difference.y, 0f);
Debug.Log(investigateCamera.transform.position);
}
}
}
it seems everything is fine on my end but for some odd the reason the camera refuses to move. Does anyone have a solution to this.
I am using URP so the camera's settings are set to this
Does anyone have any good ideas?
Thanks!
Your answer
Follow this Question
Related Questions
Pan RTS camera controller without changing elevation/zoom 0 Answers
Handling Cinemachine Freelook Camera with Touch Input to pan 0 Answers
I need to find a way to pan my camera around an object. 1 Answer
Why is Input.mousePosition returning wired values using Cinemachine 2D with dynamic following? 0 Answers