|
Hi, I have this script from the wiki, when i drag my mouse it rotates the camera around my player character but when i release my mouse the camera stays where i left it. I wan't it to snap back to it's start position.
I think the last position is stored cause when i click the screen again, my camera jumps back to it's last position when i was draggin my mouse over the screen. Any help would be appreciated.
(comments are locked)
|
|
This script should have nothing to do with your mouse button being held down if I read it correctly. Is there maybe another script that you have at work here that is based on the mouse button? Here's what your script does:
If you want it happen while the mouse is held down, you could add Input.GetMouseButton(0) or GetButton("Fire") (or whatever you have setup in your Input manager for the mouse button) to the if statement. As it was posted, the script doesn't care about the mouse button. If you want it to return to the start position on mouse release, you will need to store the start angles and move to them. You will also likely want to smooth it nicely. Doing all that, you can get a pretty good result like this, but it could possibly use some optimization and tuning:
EDIT 09/27:As Joaquin brings up, you may want to maintain the original position and orientation relative to the target as when you start the orbit. The following will do this because it does not derive orientation from the initial euler angles, but from the current relative orientation, but it will not force the camera to look at the target:
To make the camera immediately and explicitly look at the target in the above code, you could make a change something like:
or to do it more gradually, you could add a timer as was done for resetting the view with the following changed: awesome, this looks like what i need although it's not working. I did some troubleshooting and my mousebutton and mousedown arent detected. only the mouseup gets detected for some reason. And yes, my script got actived when the mouse button was down only. i was switching between the smoothfollow and this script.
Aug 27 '10 at 11:52 AM
appels
when i change the default value of resetting to false it works but the reorientation sequence doesn't stop. so i can't use the mouse anymore as long as thats running. how do i handle that ?
Aug 27 '10 at 03:23 PM
appels
i also noticed that it's not like the smoothfollow script so i will need to change that also. make it Lerp to the targets transform and rotation.
Aug 27 '10 at 03:26 PM
appels
The default value was wrong - leftovers from when I started writing the script. The reason it wouldn't stop resetting was that I had forgotten to re-add the boolean reset after I moved to code out to the reorient function.
Aug 30 '10 at 02:21 PM
skovacs1
The code is modeled after that posted in the question. The script should follow the target, but will not re-orient to the direction that the target turns. This can be done several ways - you could orient on the target's forward axis 'transform.position = rotation * target.forward * -distance + target.position;', or use rotateAround or LookAt in stead if you like. These wouldn't be smoothed. If you add 'else {//smoothfollow}' after the check for the button being held, inserting the smoothfollow code as appropriate, it should offer the desired behaviour. You will need to make adjustments though.
Aug 30 '10 at 02:46 PM
skovacs1
(comments are locked)
|
|
Hi used that script MouseOrbitImproved (Thanks to Veli V) and modified it to get a smooth rotation on drag. Here is the code:
(comments are locked)
|

related: http://unity3d.qatohost.com/questions/20525/rotating-camera-around-object-switching-different.html