Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by FoxxCommand · Mar 10, 2014 at 04:18 PM · camera movementmouse movement

How can you move main camera along x,z axis without moving along y axis with DotA/LoL mouse control

So pretty much what I've done is I've made a camera control script that takes the movement from a mouse across the window and used that to move the camera across the scene, now I've tried to make it move using transform.translate but it always seemed to move across the y axis and eventually going through the 'floor' of the whole scene if I went far enough back which is obviously a problem, so than I tried to make it change the transform.position.x/z values directly which is working but the problem I have now is that the camera has a 45 y angle rotation so if you move the mouse up and down the camera goes diagonally instead of the way you're moving the mouse, now I thought I could combat this using Trigonometry but I'm sort of stuck as to how I should apply it.

Here's what I have so far

 var horizontalSpeed : float = 0.4; //Speed to move camera along horizontal axis.
 var verticalSpeed : float = 0.4; //Speed to move camera along vertical axis.
 var key : KeyCode = KeyCode.Mouse2; //Keycode to initiate camera movement.
      
 function Update ()
 {
        
     // If button pressed, camera will move along mouse axis.
     if (Input.GetKey(key))
     {
         var h : float = horizontalSpeed * -Input.GetAxis ("Mouse Y"); //How much to move along the z axis
         var v : float = verticalSpeed * -Input.GetAxis ("Mouse X"); //How much to move along the x axis
         
         //Adding 'h' and 'v' values to move along the x,z axis'
         transform.position.z += h;
         transform.position.x += v;
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

[C#] Smooth Camera Movement Restrictions 0 Answers

How do I tell a button to move my camera!? 1 Answer

Mouse Look Help 2 Answers

Camera that both orbits and follows 1 Answer

How to rotate and move the camera with correct orientation,How to move camera after it gets rotated 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges