Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 INeedA12Step · Jan 05, 2021 at 10:02 PM · controlsscriptingproblem

Referencing a camera's orientation to affect another objects axes for control

Sorry if the title was confusing. I'm working on a project where a sphere is using gravity (at the moment) to roll on a table that pivots on its x and z axis. I have a camera that will orbit the sphere to provide the player with better visibility. The table is controlled by manipulating the rotation of the x and z axis. The problems begin when the camera moves to another angle, yet the x and z axis remain the same on the table. Controls get really wonky at that point as the player has to adjust. I'd like to somehow read the real-time x and z axis rotation of the camera for the controls of the table, if that's even possible. I've included the scripts for the table "player" and for the camera. Any help would be greatly appreciated. :-) Player.cs

void Update() { var gamepad = Gamepad.current; if (gamepad == null) return;

     else
     {
         Vector3 move = gamepad.leftStick.ReadValue();
         _yaw += -1 * (_tiltVelocityX * move.x);
         _pitch -= -1 * (_tiltVelocityY * move.y);
         transform.eulerAngles = new Vector3(_pitch, 0.0f, _yaw);
     }


 }

} FollowCamera.cs

{ [SerializeField] GameObject player; [SerializeField] float OrbitDegrees = 100f;

 Vector3 _offset;

 void Start()
 {
     _offset = (transform.position - player.transform.position);
 }

 void Update()
 {
     var gamepad = Gamepad.current;
     if (gamepad == null)
         return;
     else
     CameraOrbitControl(gamepad);
 }

 void CameraOrbitControl(Gamepad gamepad)
 {
     Vector3 move = gamepad.rightStick.ReadValue();
     transform.RotateAround(player.transform.position, Vector3.up, OrbitDegrees * move.x);
 }

-Chaun

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 INeedA12Step · Jan 05, 2021 at 11:46 PM 0
Share

I suppose another way to put it is... Can you reference one objects directional orientation and pass it on to a second object without physically moving the second? The first objects actual orientation is ever changing while the second never changes. Thanks again..

-Chaun

avatar image INeedA12Step · Jan 05, 2021 at 11:47 PM 0
Share

I noticed an answer to another question regarding orientation using:

var cameraRelativeFwd = Camera.current.transform.TransformDirection(Vector3.forward);

I actually placed "current" in lieu of mainCamera as I am using a virtual camera through Cinemachine. I'm not sure where to go from here if this will orient my table based on the camera view. I don't want the table to do anything other than pivot using the camera's local orientation. Hope I'm describing this accurately. I'm pretty new to program$$anonymous$$g so please forgive my neewbness. Lol

-Chaun

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

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

CAn soem one give me Sphere script to move in third person 0 Answers

Controls won't work in executable file 0 Answers

movement control for IOS 0 Answers

How do I get my UI controls to work in different scenes? 0 Answers

ullReferenceException: Object reference not set to an instance of an object SystemConnect.Update () (at Assets/EAO7 Scripts/Online/SystemConnect.cs:48) 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