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 Owyoow3 · Feb 27, 2015 at 08:47 AM · transformquaternioncamera rotaterotation axiscamera follow

camera follow rotation issue 3rd person controller

I'm creating a 3rd person controller and I'm having an issue with the camera rotation. The player is controlled with the left gamepad stick and the camera can rotate around the player with the right stick. Everything works fine when the player is on the ground, but my player is also able to walk on walls. I do that by setting the up transform of the player to the surface normal it is on.

When the player is on the wall I would like the camera to rotate with it, but I can't make it a child of the player because then it won't follow the player correctly. Right now the camera stays horizontal always. I made the controller with help from a tutorial so that is why it stays always horizontal, but I don't know how to change it to rotate with the player so it will always rotate around the players local up vector.

Here is the part of my code that is used for the camera follow and rotation:

 Vector3 _velocityCamSmooth = Vector3.zero;
 float _camSmoothDampTime = 0.1f;
 float _distanceUp = 2;
 float _distanceAway = 8;
 Transform _player;
 
 void LateUpdate ()
 {
     Vector3 cameraOffset = _player.position + new Vector3(0, _distanceUp, 0);
     Vector3 lookAt = cameraOffset;
     _targetPos = Vector3.zero;
 
     _lookDir = cameraOffset - transform.position;
     _lookDir.y = 0;
     _lookDir.Normalize();
 
     transform.RotateAround(cameraOffset, _player.up, _freeRotateDegPerSec * (Mathf.Abs(_input.R_Stick_X) > _rStickThres ? _input.R_Stick_X : 0f));
 
     _targetPos = cameraOffset + _player.up * _distanceUp - _lookDir * _distanceAway;
 
     transform.LookAt(lookAt);
 
     this.transform.position = Vector3.SmoothDamp(transform.position, _targetPos, ref _velocityCamSmooth, _camSmoothDampTime);
 }
 

I hope this is a clear enough explanation of the issue. The controller is supposed to be similar to the Ratchet and Clank controller where he can go up magnetic walls and the camera always rotates with him and around his local y.

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

Answer by hexagonius · Feb 28, 2015 at 11:27 AM

There's an overload of Transform.LookAt, receiving a second parameter as a world up vector. Pass in the characters up vector and the camera should stay upright with the player

Comment
Add comment · Show 1 · 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 Owyoow3 · Feb 28, 2015 at 03:17 PM 0
Share

I tried it with the player's transform as up vector but it still doesn't rotate with it. It stays horizontal so you look at the top of the character when he is on a wall ins$$anonymous$$d of looking at him from behind.

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

FPS camera is repositioning on both the X and Y axis, I only want the camera to slightly tilt (Z axis)...TIA! 2 Answers

Why does the direction of the axis changes behaviour in Quaternion.AngleAxis? 0 Answers

Increment Car Rotation along with steering Wheel 0 Answers

Third person Camera stop it from going lower than the terrian 0 Answers

Adding Rotation to a Gameobject 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