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 SimonDiamond · Apr 23, 2013 at 10:29 PM · rotationmovementpositionrelativetransformdirection

Setting z value of trans.pos relative to rotation

I'm constantly changing the z value of my camera to create a nice effect (basicly moving the camera to the side). Altough this doesn't function the way i want it to when my camera rotates, making it moving forward and backwards instead.

I've been trying to use transformDirection but i don't seem to fully understand it because i never get the desired result. If i'm not wrong i need to change the local position to world position. So that's my problem.

This is basicly what i'm doing.

MyVector.z = MyValue;

Transform.position = MyVector;

Thanks in advance for any slightest help, It's greatly appreciated.

Comment
Add comment · Show 2
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 robertbu · Apr 24, 2013 at 01:23 AM 0
Share

Can you show us the rest of your code a better description of the correct behavior? The code you show above should move the camera back and forth on the world Z axis regardless of the rotation of the camera. Is this what is happening? How is rotation changing things?

avatar image SimonDiamond · Apr 24, 2013 at 09:23 AM 0
Share

Yes the code above moves the camera according to the worlds z axis. And i'm trying to figure out a way to move the camera relative to it's rotation. Here's my actual code.

 cSharpConversion.y = $$anonymous$$idPoint.y;
 cSharpConversion.z = $$anonymous$$idPoint.z;
  
 transform.position = cSharpConversion;

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Wiki

Answer by SergeantBiscuits · Apr 24, 2013 at 09:49 AM

If you want to just "move the camera to the side", try this in the Update() function (javascript):

 var moveSpeed : float = 1;
 transform.position += transform.right * moveSpeed * Time.deltaTime;

This will make the camera move 'to the right' at one unit per second. Change 'moveSpeed' to whatever you want. If you make 'moveSpeed' negative, it will move to the left.

"transform.right" is just a one-unit-long vector pointing quite literally 'to the right' from the transform. Time.deltaTime returns the amount of time since the last tick (or 'frame').

You can also use transform.forward and transform.up for motion along the x and y axes.

Good luck!

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 SimonDiamond · Apr 24, 2013 at 11:39 AM 0
Share

Thanks for the help! Unfortunately i've done some math i just can't simply implement in transform.right. Thanks for the help anyways

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

13 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

Related Questions

Rotate an object such that it is theta degrees relative to another object 1 Answer

Tilt with rotation. 0 Answers

how to move an object, but make it stay on the ground 1 Answer

Global movement 0 Answers

Camera Relative Movement 2 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