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 Anthony0506 · May 11, 2018 at 04:29 PM · player movementcamera rotationrelative movement

How can I make movement relative to camera only after becoming stationary?

 void HandleMove()
         {
             if (canMove && pause.paused == false)
             {
                 var speed = walkSpeed;
 
                 // detect input movement
                 var moveHorizontal = Input.GetAxis("Horizontal");
                 var moveVertical = Input.GetAxis("Vertical");
                 IsMoving = moveHorizontal != 0 || moveVertical != 0;
 
       
 
          
                 var movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
                 
                 // forward is always direction of camera forward along x/z plane
                 if (useCameraMovement)
                 {
                     var camForward = Camera.main.transform.forward;
                     var camDir = new Vector3(camForward.x, 0.0f, camForward.z);
 
                     var angle = Mathf.Sign(camDir.x) * Vector3.Angle(camDir.normalized, Vector3.forward);
                     var quat = Quaternion.Euler(0f, angle, 0f) * movement;
 
                     movement = quat;
                 }
 
                 // rotate the character
                 var rot = movement * (speed / 10);
 
                 if (movement != Vector3.zero)
                 {
                     var newRotation = Quaternion.LookRotation(rot);
                     rb.rotation = Quaternion.RotateTowards(transform.rotation, newRotation, 33f);
                 }
 
                 // move the character
               
                 movement *= (speed / 10f);
 
                 var characterMovement = transform.position + movement;
                 if (attackTimer <= 0 || !IsGrounded)
                 {
                     rb.MovePosition(characterMovement);
                 }
             }
         }


I have a 3rd person camera that follows the player and that rotates in 45 degree increments, while looking down at the player. I force the movement relative to the camera, but I want this to take effect only after becoming stationary.

if i'm holding up the player moves up, away from the camera, but if he is moving up and the camera is rotated while he is moving the player rotates with the camera, and instead of staying the straight path up he is now moving on a straight path 45 degrees to the left or right of the path. i can't figure out how to make it so that the movement is only re-related to the camera after the player stops moving. i still want movement relative to the camera, just not to reset until after he is stationary. How can I improve this code to achieve this effect?

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

0 Replies

· Add your reply
  • Sort: 

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

82 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

Related Questions

How can I make WASD controls relative to camera Position? 1 Answer

Need help to make the camara rotation follow the player 0 Answers

how can i rotate the camera around the object , which follows the object??? 0 Answers

camera not rotating with body 0 Answers

Player Movement Relative to Camera? 4 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