Im trying to get my mouse to move my Main Camera which is currently an Orthographic Camera on the X and Y axis only. Can you please tell me why this isn’t working?
As far as I can tell, there’s nothing that would make this not work. Your speed values are super high, but that wouldn’t affect whether it works at all. Just to be clear, you did in fact attach this script to your camera, yes? And your project Input settings contain definitions for Mouse X and Mouse Y, and they’re properly assigned, yes?
In the future, you should copy / paste code using the ‘code tags’ so we can play with it. I just did a quick test which proves this works if the above criteria is true.
AlwaysSunny,
Thank you for the reply! I apologize for not pasting the code, will do this in the future.
My speed values were super high for test purposes because I wasn’t getting any movement response at all and wanted to rule out because my values were too low.
I did connect the script to my camera via Dragging “Main_Camera” script from Project tab onto my “Main Camera” in the Hierarchy. Selecting “Main Camera” does display the checked Script at the bottom of the Inspector.
As for the project Input settings, I thought the definitions for Mouse X and Y are assigned by default? I didn’t change them or edit anything in the “Input Manager”. Am I missing a step to load the Input Manager into my scene?
No, you’re right in that the default input settings include a proper setup for “Mouse X” and “Mouse Y”… I honestly couldn’t say what the problem might be. Based on the information you’ve provided, it should be working. As I said, I did a quick test with your code on my scene’s Main Camera which worked just fine. Can you try creating a new scene, adding just a cube or something for a frame of reference, then adding your script to the main camera? Ensure you’re not locking the movement of the camera or attempting to control it from somewhere else.
I guess another thing to try would be using Input.GetAxis(“Horizontal”) and Vertical, then using your WSAD keys or Arrow Keys. If that works, it would prove that Unity is seeing some other input device as your mouse. (two mice? a pen tablet?)
Oh my god! it was because Im using a pen tablet!
Soon as I read your last sentence, I knew that was it… Hahaha, thank you my friend. It works with the mouse. I would have spent the day trying to solve this.
Hooray! Glad I could be of assistance.
Not sure how you’d go about making Unity work with pen tablet input, if that was part of your goal. Maybe you could make a post about it here or here (Unity Answers) if you don’t find anything by searching.
AlwaysSunny,
It’s no big deal if it doesn’t work with a pin. Im developing a RTS. Im used to using a pen and having them work in RTS games which is why I assumed it would by default.
I’ve run into a new issue with the camera though. I’m trying to set it to be controlled on right click only. It works as a IF statement, but it only moves once per click. As a WHILE statement its not working. Any suggestions? Here is the code:
// Move Camera Script
var horizontalSpeed : float = 40.0;
var verticalSpeed : float = 40.0;
function Update () {
// If Right Button is clicked Camera will move.
while (Input.GetMouseButtonDown(1)) {
var h : float = horizontalSpeed * Input.GetAxis ("Mouse Y");
var v : float = verticalSpeed * Input.GetAxis ("Mouse X");
transform.Translate(v,h,0);
}
}
Probably don’t wanna be using GetMouseButtonDown(1). Instead, you should make some customizations to your project’s Input settings. I think by default the right-click of a mouse is called Fire2… You could either use
if (Input.GetAxis(“Fire2”) != 0)
or
if (Input.GetButton(“Fire2”))
not sure which is “correct” but both should work, I think. Oh, and GetButtonDown or GetMouseButtonDown or GetKeyDown only return true on the frame that the button/key was actually depressed, just like the Up variation only returns true on the frame it was released.
Dude, that worked perfectly! Man you rock. Thanks again. As you can see Im pretty new to programming, can’t wait to get to your level!
have been looking for a while and this was exatly what i was looking for and also explained very clear. Thanks guys!