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 unity_PST · Jun 01, 2012 at 05:55 PM · camerajavascriptcontrolsspaceworld

camera movement in world space, but when the rotated on y axis

I am trying to make a camera that moves exactly like the scene view camera. The camera in the scene view only moves in the x-z plane no matter what the rotation is. meaning, if you change the rotation it doesn't go right through the planar landscape in a game. But with current code. When the point the point the camera into the landscape and I press forward it would go right through it. would like it move only x and z axis.

    function Start () {
 
 }
 
 var speed = 5.0f;
 var movement = Vector3.zero;
 
 function Update () {
 
    movement.z = Input.GetAxis("Vertical");
    movement.x = Input.GetAxis("Horizontal");
   
    transform.Translate(movement * speed * Time.deltaTime, Space.self);                           
 
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Wolfram · Jun 02, 2012 at 12:28 AM

One solution would be to store the transform's y position, and reset it to that value after you've done your translation:

 ...
 var originalHeight=transform.position.y;
 transform.Translate(movement * speed * Time.deltaTime, Space.self);
 transform.position.y=originalHeight;

Note that your forward/backward movement will become very slow if you are looking way up/down. To compensate for this, scale your movement.z by the factor determined by that angle:

 // place your two movement assignments here
 var planarForward=transform.forward;
 planarForward.y=0;
 movement.z /= planarForward.magnitude;

EDIT: Note the shift in height is exactly movement.z*transform.forward.y, so instead of the originalHeight method you could just use:

 movement.y=-movement.z*transform.forward.y;
Comment
Add comment · Show 1 · Share
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
avatar image unity_PST · Jun 21, 2012 at 03:52 PM 0
Share

Thank you for the idea. I couldn't get your script to work, but I understood what you were telling.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Camera setup question 2 Answers

Character movement when I switch cameras. 0 Answers

I need help with TPS controls! 0 Answers

How to make camera position relative to a specific target. 1 Answer

Camera Orbit for spaceship 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