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 kerafrymm · Jul 19, 2013 at 06:16 PM · camerarotationmovementthird-person

3rd Person movement in relation to camera

I've been trying for a while to try and understand how to move a character in relation to a camera's rotation. At the moment the movement that I have is that W is moving away from the camera, A and D are strafing to the left or right. Moving back simply just backs the character into the camera.

I've been following the 3D Buzz tutorial for the 3rd Person Controller System and it is a great tutorial, but the movement that I described above is something that I currently don't want. I want the character to move and rotate properly in relation to the camera.

the following code are the methods that handle the actual movement and rotation of the player:

 void ProcessMotion()
     {
         // Transform MoveVector to World Space
         MoveVector = transform.TransformDirection(MoveVector);
         
         // Normalize Movevector if Magnitude is > 1
         if (MoveVector.magnitude > 1)
             MoveVector = Vector3.Normalize(MoveVector);
         
         // Multiply MoveVector by MoveSpeed
         MoveVector *= Movespeed;
         
         // Mulitply Movevector by DeltaTime
         MoveVector *= Time.deltaTime;
         
         // Move  the Character in World Space
         TP_Controller.CharacterController.Move(new Vector3(MoveVector.x, MoveVector.y, MoveVector.z));
          
     }
     void SnapAlignCharacterWithCamera()
     {
         if (MoveVector.x != 0 || MoveVector.z != 0)
         {
             transform.rotation = Quaternion.Euler(transform.eulerAngles.x,
                                                   Camera.mainCamera.transform.eulerAngles.y,
                                                   transform.eulerAngles.z);
         }
     }

I somewhat understand what everything does on a high level, but I am sadly not very well versed in things like rotation and Quaternions, and so because of this I am left in the dust because I have no idea how to use them. As far as I can understand, the method SnapAlign...() is used to tell the character that the direction that the camera is facing is forwards, but I don't know where to go from here?

So I guess my question is how do I actually move and rotate a character in relation to the camera, so that forward is moving away from the camera, backwards is running towards it and left and right are moving to the left or to the right of the camera.

[EDIT] I may have described my problem a little weirdly, sorry. When I move my character, the player is rotated so that it is facing forward in relation to the character, which causes the problems i am having.

Below is a crudely drawn diagram. (Sorry, I am truly no artist) The player faces forwards at all times, no matter which input is being applied (left, right, back etc.) I need to get get it so that the character rotates properly, e.g it will rotate left to move left.

alt text

diagram1.jpg (49.8 kB)
Comment
Add comment · Show 3
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 robertbu · Jul 19, 2013 at 06:19 PM 0
Share

Line 4 is what takes a local direction and transform it into a world direction. Right now you are using 'transform' which is the transform of the character to make this transformation. That means you are making your moves relative to the character. I believe you will get what you want if you use the transform of the camera to make that transformation:

 $$anonymous$$oveVector = Camera.main.transform.TransformDirection($$anonymous$$oveVector);
avatar image robertbu · Jul 19, 2013 at 07:27 PM 0
Share

I assume from the 'EDIT' that I did not understand your question. After reading your new text, I still don't understand the problem. A drawing might help as well as the relationship between the camera and the character.

avatar image kerafrymm · Jul 19, 2013 at 07:52 PM 0
Share

I added a picture that might make things more clear. Sorry I'm really not very good at explaining things, especially things I don't understand myself

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Professor Snake · Jul 19, 2013 at 08:21 PM

One solution would be to only rotate the character model based on the direction its moving, while keeping the character controller's rotation the same. Otherwise, you can use the camera's transform.forward and transform.right to get the direction it's facing, but it's not as elegant as the previous solution.

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

18 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

Related Questions

RTS Camera Rotation and Movement 0 Answers

How to make my player look in the direction of its movement? 3 Answers

camera slides and bounces while moving C# 1 Answer

Global movement 0 Answers

Move Camera around an object 2 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