Hi,
i want to move an object with the mouse. This is my code:
mousePos= Input.mousePosition;
mousePos.z = -Camera.main.transform.position.z;
mousePos = Camera.main.ScreenToWorldPoint( mousePos );
This works fine. But my problem is the camera. During the drag my camera is moving smoothly( because i attach the camera to an enemy). Therefore the object is also moving altough my mouse isnt moving.
I hope you understand the problem, who can help me?
…edit: is it possible to drag an object without involving the camera?
Hi Bumba
Out of curiosity, what are you using this to do in the game?
I’m not sure if I understand your question-- maybe with a little more information we can figure it out.
Do you want the object to remain still when the camera is moving?
How are you updating the object’s position?
What exactly is the behavior you expect between the mouse and object during camera movement?
A little more code might be helpful too!
yes i want the object to remain still when the camera is moving.
in the update method i change the postion from the object:
mousePos= Input.mousePosition;
mousePos.z = -Camera.main.transform.position.z;
mousePos = Camera.main.ScreenToWorldPoint( mousePos );
this.transform.position = mousePos;
i want to drag the object around so the enemy will follow it. But the camera is attached to the enemy. Therefore when the mouse stands still and the enemy is moving the camera is moving and also the object
I’m still not sure if I understand what you are trying to do, it sounds kind of confusing if you are trying to move an object, which the camera is following, while at the same time using the camera’s screenToWorld data to move the object… and especially on an enemy NPC…
but if you do not want the object to move with the camera when the mouse is still, why not test this situation (maybe using Input.GetMouseButton) and simply not call the part of your Update where the object is moved?
I’m probably misunderstanding your request though. I’m still very curious to know how this would work in your gameplay.
yes i tried this option. Then the object stands still. But when the camera is moving the mousepointer is moving too. And the mousepointer isnt anymore at the same position as the object.
Code:
if((Input.mousePosition.x-lastInput.x) !=0 (Input.mousePosition.y-lastInput.y) !=0){
mousePos= Input.mousePosition;
mousePos.z = -Camera.main.transform.position.z;
mousePos = Camera.main.ScreenToWorldPoint( mousePos );
this.transform.position = mousePos;
}
i consider to use a second camera, from which the whole level will be seen. Then using ScreentoWorld.
edit: … hmm therefore the camera must be enabled
Is it possible to drag an object without involving the camera?
can somebody please help me? I do not know what should i do