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 /
avatar image
0
Question by Mozzi27 · Sep 02, 2017 at 06:32 PM · unity 5rotationthird person controllerthird person shootermouse aim

Make Third Person Character Rotate

Hi, after tons of research and no answers, i have decided to make my first post and see how it goes :)

I am trying to create a very specific Third Person Character controller, but instead of it being like most third person shooters where the camera can look around the player, i would like the character to rotate with the camera (which is moved by the mouse x and y) so that the characters front is always facing away from the camera. A good example would be: https://youtu.be/rmtBOPHHQCY?t=273 or https://youtu.be/m1w8jehDrzo?t=408

Take a look at some of he Gameplay above and as you can see, the character is rotating with the camera and always facing the crosshair, in the middle.

So is there anyone out there who would be able to point me in the right direction? Any help is appreciated. Thanks in advance!

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
3

Answer by unidad2pete · Sep 02, 2017 at 07:30 PM

You need adjust the next tips to your preferences but the base is this:

Makes a new empty gameObject child of your player, this child we named CamX. Makes a new empty gameObject child of CamX , named CamY, add the camera to this gameObject, and move the position and rotation like you want.

 public float mouseSpeed = 3;
     public Transform player;
     public Camera yourCam;
 
     private void Update()
     {
         float X = Input.GetAxis("Mouse X") * mouseSpeed;
         float Y = Input.GetAxis("Mouse Y") * mouseSpeed;
 
         player.Rotate(0, X, 0); // Player rotates on Y axis, your Cam is child, then rotates too
 
 
         // To scurity check to not rotate 360º 
         if (yourCam.transform.eulerAngles.x + (-Y) > 80 && yourCam.transform.eulerAngles.x + (-Y) < 280)
         { }
         else
         {
 
             yourCam.transform.RotateAround(player.position, yourCam.transform.right, -Y);
         }
     }

This is not perfect, do you need adjust positions, angles and maybe other postion to rotate Around that not is player. But you can get the idea.

Comment
Add comment · Show 3 · 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 Mozzi27 · Sep 02, 2017 at 09:58 PM 0
Share

Thanks for your answer, I'll try this when I get the chance

avatar image yade_123 · Jun 03, 2018 at 01:51 PM 0
Share

@unidad2pete Wow working perfectly thanks mate solved my problem..sad how the person never came back to upvote your answer but one little question ..why do we need the "camx"and "camy"? the code worked fine without those or did i miss something...

avatar image AdvaitKelkar · Dec 14, 2019 at 03:02 AM 0
Share

Thank you so much! This worked like a charm.

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

159 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 avatar image avatar image

Related Questions

Unity Asset Prefab Bug ThirdPersonController (left rotating bug / Snapping forward Always) 3 Answers

My Obstacle Rotations Are Not Correct 0 Answers

Third Person Shooter (TPS) aiming like Uncharted / MaxPayne3 0 Answers

Setting up Animation for Third Person Controller 0 Answers

How can I turn the direction of bicycle in unity with animations. 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