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 Davud · Oct 16, 2014 at 07:44 PM · orbitcamera rotation

How to make a GTA camera orbit

I am researching about TPS cameras . If i use LookAt(target), player stands in the middle of view and crosshair on it. GTA5, Just Cause 2 have nice cameras. Player model stands on bit left side. You can rotate around them with camera and crosshair is in the middle. How can i put player on left side in any amount with a variable?

 Vector3 cameraOrientationVector= new Vector3(1,0,-2);    
     public float crosshairSize;    
     public Transform target;
     public Texture2D crosshairImage;
     public float turnSpeed=5f;
     private Vector3 offsetX;
     private Vector3 offsetY;
 
         
 
     void Start ()
     {
     
         offsetX = new Vector3 (10, 0, -2);
         offsetY = new Vector3 (10, 0, -2);
 
     }
     void OnGUI()
     {
         
 
         float xMin = (Screen.width / 2) - (crosshairImage.width / 2);
         float yMin = (Screen.height / 2) - (crosshairImage.height / 2);
         
         
         Rect position = new Rect((Screen.width - crosshairSize) * 0.5f, (Screen.height - crosshairSize) * 0.5f, crosshairSize, crosshairSize);
         GUI.DrawTexture(new Rect(xMin, yMin, crosshairImage.width, crosshairImage.height), crosshairImage);
         
         
     }
     void LateUpdate ()
     {
         offsetX = Quaternion.AngleAxis (Input.GetAxis("Mouse X") * turnSpeed, Vector3.up) * offsetX;
         offsetY = Quaternion.AngleAxis (Input.GetAxis("Mouse X") * turnSpeed, Vector3.right) * offsetY;
 
 
 
         transform.position = target.position + offsetX; 
         transform.LookAt(target); // so crosshair on player
         
         //transform.position = target.position + cameraOrientationVector;
         
 
         
     
     }
 
Comment
Add comment · Show 4
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 Davud · Oct 19, 2014 at 05:52 PM 0
Share

For now i just moved crosshair to right. Still wondering how do they move lookAt(target) to right. If i find something, i will post here.

avatar image kburkhart84 · Oct 19, 2014 at 06:09 PM 0
Share

It depends on whether you are using an actual separate object or just storing things in variables. Either case involves vector math. If I have an actual object, I start by making that object face back to the camera to make its forward vector be pointing from it to the camera. Then you can make the object move some distance to the left via the left vector. I think Unity can get these vectors for you automatically via the transform component if you are using an object. If you are using variables it can be a little more complicated, but the same idea applies. You would just have to get your own version of the "left" vector.

avatar image Davud · Oct 19, 2014 at 06:47 PM 0
Share

Then i need to study vector math,thanks again.

avatar image kburkhart84 · Oct 20, 2014 at 04:05 AM 0
Share

Yup, understanding Vectors, how they can relate to each other, especially special things like cross/dot product, and then quaternions(not needed for this camera most likely except what Unity does internally) will get you far. Understanding the actual math behind the things isn't usually as important, but understanding for example that the dot product gives a value saying how "parallel" a pair of vectors are can help, for example if you want to use it to see if something sees something else, and you don't have understand how to get the dot product to learn how to use it.

1 Reply

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

Answer by kburkhart84 · Oct 16, 2014 at 10:42 PM

I'm no expert on cameras, but let me get you started.

Think logically what you want to do. If you look at the player directly, it will do exactly that, which isn't what you want. Instead, you want to look at something else, which can vary. So, create another object(or you can just store it in variables). This object could be either where the player is pointing, it could hang out to the right ear of the player avatar, or different things. Then, make your camera look at that instead. This concept is great as well for example if you want to change things, like near/far, or maybe have the view either get ahead of where the player is moving, or lag behind, you can adjust only the separate object and keep the camera looking at the same thing.

The trick to this is not so much the separate object, but the position of the camera. You would likely want to have some method of detecting what direction the player is looking, and modify that vector to give a sort of angle and position where you think the camera should be. Draw it out, write some simple vectors, see how they are related and then convert them to get what you want in code.

The last thing I should mention is that you should almost always lerp/tween your camera, both the position and the lookAt spot, in order to keep things smooth. The main exception to this is if you want an instant "look" at something somewhere else, and even then sometimes game designers want to make it smooth instead of instant.

Comment
Add comment · Show 4 · 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 Davud · Oct 17, 2014 at 07:56 AM 0
Share

Thanks for your guide. It will be very helpful on understanding other tps cam scripts.

avatar image Christian.Tucker · Oct 17, 2014 at 09:10 AM 0
Share

How was this an answer at all? Anyway, look at the Camera.ViewportPointToRay function, use this and fire a raycast, then have your player rotate towards the rays direction. You could just use a regular camera with smooth-follow to achieve this effect if you toy with the settings.

avatar image kburkhart84 · Oct 17, 2014 at 04:30 PM 0
Share

Honestly, I didn't expect it to get accepted as the answer. $$anonymous$$y intention, considering the Davud appears to have some knowledge was to say how I would go about it logically, not write a script for him.

$$anonymous$$aybe I'm crazy, but understanding the logic of the situation will help more in the long run than just copypasta scripts....just sayin.

avatar image Davud · Oct 30, 2014 at 05:52 PM 0
Share

I found the code a week ago. It's just the way kburkhart84 has explained. Teddy W shared his unity project. You can find necessary codes from there.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How Do I Make The Camera Orbit Stop at a Certain Point? 0 Answers

Player movement against skybox 0 Answers

Third Person Camera Orbit 0 Answers

Making my camera script snap back to original position 1 Answer

How do you move multiple objects in an orbit? 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