Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Psyk16 · Sep 20, 2016 at 04:52 AM · cameraorientation

Orientation Issue 1

Hi everybody. First time posting. I'm creating a game similar to the 3D roller ball tutorial, but I would like to add in the function of changing your camera angles so I can maybe hide some items and the player will need to rotate the camera to see around corners. I've added 3 other cameras, and set them around my character to give me a 360* view. My question is this - is there a way for me to change the orientation of my player so that when I switch to another camera, my player's orientation switches with it? Currently, when I switch to a different camera, my players orientation stays the same, so hitting UP now actually makes my player go RIGHT because he's using the original orientation input.

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 Fornoreason1000 · Sep 20, 2016 at 07:56 AM 0
Share

you should have a look at the character controller scripts that come with unity. basically you need to transform the direction of your input to the rotation(specifically the y rotation) of the current camera. in English that means you move right relative the your orientation, not relative to the world.

heres how I would do it. using C# if that matters

  1. Detect when you orientation changes, this can be as simple as an event when you change your orientation. you could even pass the active camera into a function.

  2. Store the current orientation now that you have detected its changed. when need to hold onto a reference of this camera so we can use it to modify our direction of movement. you can do this by creating a member wise variable.

  3. Get the Camera's to the block of code that calculates movement. GetComponent() is useful here.

  4. $$anonymous$$ultiply your input vector by the current cameras rotation

avatar image Psyk16 Fornoreason1000 · Sep 21, 2016 at 05:43 AM 0
Share

Alrighty...so I gave what you said a shot. I think my C# skills were nowhere near ready to do this lol. I think I did steps 1-3 correctly...but i can't seem to apply the camera's angle to my movement. I keep getting errors saying things like "you can't multiply a Vector3 x Vector3), or when I pull out the individual values of the camera angles, and multiply my input by it, it simply makes my x values 65* stronger, so I fly through the walls when I move. Can you possibly give me an example of how you would apply the camera's angles to my movement? This is the code I use for my movement. Thanks!!!

``` void FixedUpdate() { float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical"); Vector3 movement = new Vector3(moveHorizontal, 0f, moveVertical); rb.AddForce(movement * speed); } ```

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Psyk16 · Sep 20, 2016 at 07:23 PM

This looks fantastic! thank you so much for the quick response. I'm still very much a beginner of C#, but I think I can translate what you said in text into code. I'll be giving this a try tonight. You rock :)

Comment
Add comment · 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

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

92 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 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 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 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 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

Maintain fixed vision while the player turn 0 Answers

How to get the object relative pose with respect to camera (position+rotation) 1 Answer

Change orientation of smooth follow camera? 0 Answers

Mouse Look Right Click Bounce 0 Answers

How to get the camera to follow a prefab? 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