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 /
avatar image
0
Question by HarryBGamer2570 · Jan 05 at 08:15 PM · camera movementcamera rotation3rd person camera

Help with 3rd person camera

In short I want to recreate the 3rd person camera from the game Unturned. In it, the camera is a bit behind and hovering over the player (over the shoulder camera), while the character is always looking forward at the cursor/center of the screen (the cursor is CursorLockMode.Locked). Basically a 3rd person aim camera.

I have this code:

 float x = Input.GetAxis("Mouse X") * sensitivity * Time.deltaTime;
 float y = Input.GetAxis("Mouse Y") * sensitivity * Time.deltaTime;

 // transform = camera object
 // transform.parent = EmptyObject (with character controller)
 transform.RotateAround(transform.parent.position, Vector3.left, y);
 transform.parent.Rotate(Vector3.up * x);

which comes to the thing I want, really close, but there is a big issue that I tried to figure out so I can explain it, but I couldn't. You could also do something like:

 transform.parent.Rotate(Vector3.left * y);
 transform.parent.Rotate(Vector3.up * x);

Again close but not really, it kind-a starts rotating on the z axis.

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
0
Best Answer

Answer by HarryBGamer2570 · Jan 17 at 08:54 PM

I actually found a wait to do it.

First I split the players character (a cylinder) into top (body) and bottom (legs) part. Then I made an anchor point for the top part that is at the cut between both parts, so the top part doesn't rotate around it's self, but around the anchor point.

Then with C#

 playerObject.transform.Rotate(Vector3.up * x);

-rotate the player, which actually is just a character controller

 if (rotation < 90 && rotation > -90)
 {
     playerObject.transform.Find("Anchor").transform.Rotate(Vector3.left * y);
     //playerObject contains the Legs and the Anchor, to which (the anchor) the body is parented to
 }

-rotate the anchor (and with it the body) in the direction the cursor is (vertical), but limiting the rotation of the body so it doesn't go rotating 360

then with:

 playerObject.transform.Find("Legs").transform.rotation = playerObject.transform.rotation;
 playerObject.transform.Find("Anchor").transform.eulerAngles = new Vector3(playerObject.transform.Find("Anchor").transform.eulerAngles.x, playerObject.transform.Find("Legs").transform.eulerAngles.y, 0f);

-rotate the legs where the cursor is pointing at (horizontal axis) -and then with the legs rotate the body with them, but with global/world axis

But we wouldn't want only in third person out character to be able to bend over or look at the sun, so for first person basically everything till now, without the last line (where we rotate globally).

This should be it, at least for me it is, because it does everything I need it to do. Here are some results:

alt text


2.png (12.0 kB)
1.png (40.6 kB)
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

134 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

Related Questions

First person POV to third person POV? 1 Answer

3rd person orbiting camera in vr 1 Answer

FPS cam for Roll -a-Ball like game 1 Answer

How to stop 3rd person camera going throught walls ? 1 Answer

Object Movement in Camera facing direction 0 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