Unity Community |

Hello again, my party people!
I have a reticle that is layered and centered over the mouse cursor just like any other FPS, but in my game the camera doesn't follow the mouse cursor. Yes I want it to be that way.
What I'd like to do is the have the camera slightly pan up, down, left, or right a certain number of degrees before ceasing to pan when the cursor touches the top, bottom, left, or right borders of the screen.
How would I achieve this? I'd need to check the mouse position for the -x, x, y, and -y, coordinates and then what? How would I slowly pan the camera in the given direction???
Thank you in advance!
An image for assistance:
EDIT/UPDATE:
I have written the code. Here it is:
Code:
var leftSide : float; var rightSide : float; var Top : float; var Bottom : float; //Does the mouse hit the Left area? } //Does the mouse hit the Right area? } //Does the mouse hit the Top area? } //Does the mouse hit the Bottom area? } }
This code identifies all four zones and moves the camera accordingly. Which is fine and dandy. Here is what I really need help with. I have three things I need to do:
1. Have the camera latch onto the mouse when it enters any of the four zones
2. Set a limit on how far the camera can drift
3. Have the camera go back to the original static position (Unparenting it from the mouse) when the mouse moves back to the center zone
What was this about Lerps??? Thanks!- YA
Last edited by youngapprentice; 05-01-2012 at 07:14 PM.
Current games:
Asteroid Field (Unity)
Dress up Obama (Flash)
Try 'em out! More great games by YA Productions are on their way!
What I am thinking you could do is like this,
Code:
{ { } { } { } { } else { } }
Or use transform.position to move the camera, euler is for rotating the camera. And then you could use a lerp for a smooth transition back to the original position.
I would Lerp the camera rotation vector (in both axes), third parameter would be mousePosition/Screen.height/widht.
Looking for helpfull hands with an action/RPG fan game -- link
Remember to have a nice day and smile!
I don't quite understand what you guys are saying. I will update the first post as well. This is what I have so far:
Code:
var leftSide : float; var rightSide : float; var Top : float; var Bottom : float; //Does the mouse hit the Left area? } //Does the mouse hit the Right area? } //Does the mouse hit the Top area? } //Does the mouse hit the Bottom area? } }
This code identifies all four zones and moves the camera accordingly. Which is fine and dandy. Here is what I really need help with. I have three things I need to do:
1. Have the camera latch onto the mouse when it enters any of the four zones
2. Set a limit on how far the camera can drift
3. Have the camera go back to the original static position (Unparenting it from the mouse) when the mouse moves back to the center zone
What was this about Lerps??? Thanks!- YA
Current games:
Asteroid Field (Unity)
Dress up Obama (Flash)
Try 'em out! More great games by YA Productions are on their way!
While I was writing, I actually came up with a different solutionUntested.
Code:
float CameraPan; // set how much the camera can pan; { camera.position.localEulerAngles = Vector3.ClampMagnitude(new Vector3 ( 0, Input.GetAxis( "Mouse X" ) , 0 ), CameraPan); // change camera rotation up to a certain degree } else camera.position.localEulerAngles = Vector3.zero; // make sure camera returns to center if we are no longer panning
You can do the same with up and down.
Sorry it's in C#, but conversion shouldn't be much of a problem![]()
Last edited by Zethariel1; 05-02-2012 at 12:21 AM.
Looking for helpfull hands with an action/RPG fan game -- link
Remember to have a nice day and smile!
Oh, BABY! Thank you Zethariel! This is exactly what I need. I will implement this into the code later today or when I have the time and will update with results. Thanks guys!-YA
Current games:
Asteroid Field (Unity)
Dress up Obama (Flash)
Try 'em out! More great games by YA Productions are on their way!
In the line where it says
camera.position.localEulerAngles = Vector3.ClampMagnitude(new Vector3 ( 0, Input.GetAxis( "Mouse X" ) , 0 ), CameraPan); // change camera rotation up to a certain degree
What is the 'Input.GetAxis("Mouse X)"???
What do I put there? Thanks!-YA
Current games:
Asteroid Field (Unity)
Dress up Obama (Flash)
Try 'em out! More great games by YA Productions are on their way!
Looking for helpfull hands with an action/RPG fan game -- link
Remember to have a nice day and smile!
Oh! So you are saying that the script responds to any movement on the x axis from the mouse. Genius. I failed the first time trying to convert it to javascript, but I'll try again. Thanks! - YA
Current games:
Asteroid Field (Unity)
Dress up Obama (Flash)
Try 'em out! More great games by YA Productions are on their way!
I was able to successfully implement it BUT I need to know this: Is there any way to change the activation zone to the boundaries of the GAME SCREEN instead of the ENTIRE SCREEN? No I am not yelling at you. Just wanted to make the words stand out
Thanks!-YA
Current games:
Asteroid Field (Unity)
Dress up Obama (Flash)
Try 'em out! More great games by YA Productions are on their way!