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
1
Question by EpicSnareDrum · May 05, 2015 at 06:20 AM · cameracontrolthird-person

Third Person Camera Control

Hi,

I am making a game which plays from the third person perspective and am having a bit of trouble with the camera control. I am trying to get similar camera play as that of Assassin's Creed and Warframe, where the character model stays at one rotation while the camera orbits around him and when the forward movement key is pressed, the character will rotate smoothly to that rotation, but ONLY on the "y" axis.

What I've tried using (but to no avail) is this:

 function Update () 
 {
     if(Input.GetKey("w"))
     {
         transform.rotation =
             Quaternion.Slerp(transform.rotation, CameraController.rotation, 
             rotSpeed * Time.deltaTime);
     }
 }

Any help or suggestions are greatly appreciated, thanks.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by JinJin · May 05, 2015 at 10:32 AM

use Mathf.Lerp to interpolate transform.rotation.eulerAngles.y with CameraController.rotation.eulerAngles.y

 Vector3 eulerAngles = transform.rotation.eulerAngles;
 Mathf.Lerp( eulerAngles.y, CameraController.rotation.eulerAngles.y, rotSpeed * Time.deltaTime );
 transform.rotation.eulerAngles = eulerAngles;
Comment
Add comment · Show 5 · 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 EpicSnareDrum · May 05, 2015 at 07:10 PM 0
Share

I've tried this, but it isn't doing anything at all.... Have I missed something?

Full script:

 #pragma strict
 
 private var anim : Animator;
 
 var CameraController : Transform;
 var rotSpeed : float;
 
 function Start ()
 {
     anim = GetComponent("Animator");
 }
 
 function Update () 
 {
     var pEulerAngles : Vector3 = transform.rotation.eulerAngles;
 
     if(Input.Get$$anonymous$$ey("w"))
     {
         $$anonymous$$athf.Lerp(pEulerAngles.y, CameraController.rotation.eulerAngles.y,
         rotSpeed * Time.deltaTime);
         transform.rotation.eulerAngles = pEulerAngles;
     }
     
     
     //Animation
     var h : float = Input.GetAxis("Horizontal");
     var v : float = Input.GetAxis("Vertical");
     anim.SetFloat("Speed", v);
     anim.SetFloat("Direction", h);
 }
avatar image JinJin · May 06, 2015 at 08:22 AM 0
Share

try without $$anonymous$$athf.Lerp()

  Vector3 eulerAngles = transform.eulerAngles;
  eulerAngles.y = CameraController.eulerAngles.y;
  transform.eulerAngles = eulerAngles;
avatar image EpicSnareDrum · May 06, 2015 at 12:40 PM 0
Share

It works without $$anonymous$$athf.Lerp, but not how I need it too.. Without the $$anonymous$$athf statement, it simply snaps to the direction the camera is facing. I need it to smoothly rotate to the camera's Y rotation.

avatar image JinJin · May 06, 2015 at 01:20 PM 0
Share

you can find your bug if you write to your unity console:

  if(Input.Get$$anonymous$$ey("w"))
  {
      Debug.Log(pEulerAngles.y);
      Debug.Log(CameraController.rotation.eulerAngles.y);
      Debug.Log(rotSpeed);
 
      $$anonymous$$athf.Lerp(pEulerAngles.y, CameraController.rotation.eulerAngles.y,
      rotSpeed * Time.deltaTime);
 
      Debug.Log(pEulerAngles.y);
 
      transform.rotation.eulerAngles = pEulerAngles;
  }

use this and you will see what goes wrong in the editor console

just compare the first and second Debug.Log(pEulerAngles.y); to see if it changed

avatar image EpicSnareDrum · May 06, 2015 at 01:35 PM 0
Share

Thanks, but I came to a different conclusion:

 var angle : float = $$anonymous$$athf.LerpAngle(transform.rotation.eulerAngles.y, 
     CameraController.rotation.eulerAngles.y,
     rotSpeed * Time.deltaTime);
     
     if(Input.Get$$anonymous$$ey("w"))
     {
         transform.rotation.eulerAngles = Vector3(0,angle,0);
     }

Thank you for your time regardless!

avatar image
0

Answer by SavaTim · Jun 12, 2019 at 11:11 PM

Camera Controller https://youtu.be/ETqL_SQ7BbU

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

21 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

Related Questions

How to make camera position relative to a specific target. 1 Answer

Camera Control Help 0 Answers

character switching on collision 1 Answer

Mouse orbit + Smooth follow script question 0 Answers

3rd person camera reset bug 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