• 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 Bobbysolo100 · Feb 01, 2019 at 09:56 PM · rigidbodycamera-movementcamera rotatethird-person

How can I make the player look at the camera while rotating?

I made a camera script for my 3d platform character but having some slight issue. When ever I move my player with the rigidbody, I can move just fine. But when ever I rotate my camera left or right, and while pushing the key W (as in going forward) the player is not going with the camera rotation. Instead its going one direction and that's it. How can this be solved?

Comment
Add comment · Show 1
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 tormentoarmagedoom · Feb 01, 2019 at 10:46 PM 0
Share

post your camera movement script

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by UltraGearGames · Feb 04, 2019 at 02:24 PM

Possibly, by setting the Player's rotation to the camera's horizontal rotation whenever W or S is pressed. I can try write the code if you want.

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

Answer by Bobbysolo100 · Feb 04, 2019 at 03:09 PM

If it's not too much trouble But when the camera rotates, the player should stand still while I push a key,he rotates

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

Answer by UrielKane · Feb 04, 2019 at 05:15 PM

I came across the same problem a few weeks ago when starting to use rigidbody for my character controller script. I should test before posting but if i remember correctly, the way of solving this issue. Its by transforming the direction before apply any movement or force to the rigidbody. Something like this.


 void FixedUpdate()
     {
         moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
         moveDirection = transform.TransformDirection(moveDirection);
 
         _body.MovePosition(_body.position + moveDirection * Speed * Time.fixedDeltaTime);
     }


I have setup a private vector3 on the initialization of the variables, then i read the inputs like shown in the code sample. The second line is what you should be testing on, becouse that transform the direction of the vector3 called moveDirection. moveDirection as it is right there, is "drawing" the shape of a + on the world matrix, so there is no relative direction to the camera rotation. By setting the moveDirection vector to be relative of the transform then the axis will be corrected to be facing the direction of the transform you are rotating with the camera. When you are applying directions for an object to move along they use world direction by default, so in order to change that you have to use that "transform.TransformDirection(vector3)" line.

I hope it helps, at least thats what solved my own problem a few weeks ago.

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 Bobbysolo100 · Feb 04, 2019 at 05:20 PM 0
Share

This is rigidbody correct?

avatar image Bobbysolo100 · Feb 04, 2019 at 05:25 PM 0
Share

Also it's pretty hard to tell what your vector3 is

avatar image UrielKane Bobbysolo100 · Feb 07, 2019 at 01:17 AM 0
Share

Yes its a rigidbody, the code is not completed becouse i defined some variables outside the fixedupdate. If you need it i can give you the full code, its not very large yet im messing around other areas of the project right now. The thing is that the script uses a reference to another script witch has a loot of static and public variables to track use inputs, thats why i didnt give the full code. But anyway you should be able to solve your problem with what i give you. Just make a public variables type float with the name of "Speed" and a public variable called _body type rigidbody, or simple call a getcomponent if you want. Then the code should work as it is and you should be able to start moving and having the corrected direction. This means that if you rotate the rigidbody then the code will move the rigidbody along it local axis ins$$anonymous$$d of global axis.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

141 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

Related Questions

MoveRotation stops working while player is moving 0 Answers

How can I rotate my camera when player has rigidbody? 0 Answers

I only rotated X, but Y and Z are shifting as well when I play the game. 1 Answer

How to clamp Y rotation of camera? 1 Answer

Unity 2D... getting accurate X and Y values of camera when rotating it. 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