• 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
1
Question by ferruccio · Jul 26, 2012 at 09:20 PM · camerarotatelookattranslate

Use lookAt and transform.translate at the same time

Hi, I'm trying to get a camera, pointing down towards a rectangle, to move on the x axis using the accelerometer and, at the same time, to always point at the center of the rectangle (which is, coordinates 0,0,0). So, the camera should move and rotate to always look at the center of the rectangle. The purpose is to give a sense of "false 3D", for lack of a better description.

I can make the camera move, but I can't make it rotate accordingly. When I use lookAt, the whole thing spins on the y axis instead of rotating on z axis. It looks like I can't use transform.translate and lookAt in the same function.

I'm really at a loss, here. I literally can't think of any way to fix this. It would be awesome if someone could help.

Anyway, here is the code I'm using to make it move. What should I add/change?

 function Start () {
 
 }
 var camSpeed = 20;
 
 function Update () {
 
 //var dir : Vector3 = Vector3.zero;
 var dir : Vector3;
 dir.x = -Input.acceleration.y; 
 dir *= Time.deltaTime;
 transform.Translate (dir * camSpeed);
 
 }
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
2
Best Answer

Answer by whydoidoit · Jul 26, 2012 at 09:22 PM

Your problem is using Translate without a specific second parameter of Space.world - currently the translation happens in the rotation of the object - which gives you the spinning effect. You presumably want movement in world coordinates and then the look at should keep it centered...

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 ferruccio · Jul 29, 2012 at 09:58 PM 0
Share

Thanks! I also had to change another couple of things (which is, the orientation of the objects and the gravity), but now the whole scene is better layed out and it works perfectly. Thanks again!

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Why my camera rotates around gameobject 1 Answer

Scripting Issue With Top Down Mouse Movement 1 Answer

How do I rotate a Rigidbody to a surface normal AND use camera rotation? 1 Answer

How to rig a cutscene Camera back to it's original place 1 Answer

Character controls seen in Amnesia 4 Answers


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