Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Camera Mouse

Discussion in 'Scripting' started by Kainanteh, Sep 3, 2014.

  1. Kainanteh

    Kainanteh

    Joined:
    Sep 3, 2014
    Posts:
    14
    How can I do the camera follow the mouse? Like Age of Empires or Warcraft
     
  2. c00pala

    c00pala

    Joined:
    Jul 6, 2014
    Posts:
    5
    Hi Kainanteh,

    There are a lot of really good tutorials covering this exact topic; try searching for 'Unity RTS Camera tutorial'.

    Here's a few quick searches for you:

    https://www.google.com.au/?gfe_rd=cr&ei=obkHVN_-DuXC8ged2oHYCw&gws_rd=ssl#q=Unity3d RTS Camera Tutorial&spell=1

    http://unity3d.com/search?gq=RTS Camera
    I highly recommend you try searching and reading through previous posts before asking here, you'll get a much better understanding in the long run and you'll often find the answers a lot quicker than waiting for someone to reply.

    To point you in the general direction though, you're looking for an RTS camera setup.

    This would normally involve having a script attached to your game camera, or a camera object, that alters its movement based on your mouse position (or other input - e.g. arrow keys, or mouse wheel) but it's entirely dependent on how you want it to work.

    I'm still a bit new myself but one way I'd personally do this is to, within the camera script, define points on the screen or in the game world at which you'd like the camera to move (e.g. the left most side of the screen) or even a distance away from the camera (e.g. myCameraObject.transform.position.x - 100), then check to see when the mouse is near/over/past those points (there's a lot of info out there on how to find and use the mouse position) and use something like transform.translate, transform.position or transform.localposition to move the camera accordingly.

    Have a look through the links above and see if you can make a start. If you try and still can't get it to work then come back and post the exact issues you're having along with some samples of your code.

    Hope this helps, good luck!
     
  3. Kainanteh

    Kainanteh

    Joined:
    Sep 3, 2014
    Posts:
    14
    Thanks for the help