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 Impmaster · Jun 05, 2016 at 04:16 PM · vector3

Why does my vector pan my character slightly to the side?

I'm modifying the default FirstPersonController script to have a jetpack, and I've got it mostly down. However, there's an annoying bug where if I fly at an angle to the x or z axes it'll make me strafe slightly to the side.

I think it's because I clamp the x and z distances. Please check my code and tell me what's wrong.

I did notice that when I set the FlyModifier to a very small number like 0.1, I did stop the strafing, but it took forever to start building momentum.

     // always move along the camera forward as it is the direction that it being aimed at
     Vector3 desiredMove = transform.forward*m_Input.y + transform.right*m_Input.x;

     // get a normal for the surface that is being touched to move along it
     RaycastHit hitInfo;
     Physics.SphereCast(transform.position, m_CharacterController.radius, Vector3.down, out hitInfo,
                        m_CharacterController.height/2f);
     desiredMove = Vector3.ProjectOnPlane(desiredMove, hitInfo.normal).normalized;

     //If just a regular jump, do regular movement, otherwise add momentum
     if (!m_Flying) {          
         
         //On the ground
         if (m_CharacterController.isGrounded) {
             m_MoveDir.x = desiredMove.x*speed;
             m_MoveDir.z = desiredMove.z*speed;    
         } else { //Falling through the air
             m_MoveDir.x += desiredMove.x*speed*m_flyModifier*Time.deltaTime;
             m_MoveDir.z += desiredMove.z*speed*m_flyModifier*Time.deltaTime;
     
             m_MoveDir.x = Vector2.ClampMagnitude(new Vector2(m_MoveDir.x, m_MoveDir.z), m_RunSpeed).x;
             m_MoveDir.z = Vector2.ClampMagnitude(new Vector2(m_MoveDir.x, m_MoveDir.z), m_RunSpeed).y;             
         }
     //Jetpacking                              
     } else {
         
         m_MoveDir.x += desiredMove.x*speed*m_flyModifier*Time.deltaTime;
         m_MoveDir.z += desiredMove.z*speed*m_flyModifier*Time.deltaTime;
         
         m_MoveDir.x = Vector2.ClampMagnitude(new Vector2(m_MoveDir.x, m_MoveDir.z), m_RunSpeed).x;
         m_MoveDir.z = Vector2.ClampMagnitude(new Vector2(m_MoveDir.x, m_MoveDir.z), m_RunSpeed).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 Impmaster · Jun 07, 2016 at 02:53 PM

I figured it out. I had these updating one after another:

m_MoveDir.x = Vector2.ClampMagnitude(new Vector2(m_MoveDir.x, m_MoveDir.z), m_RunSpeed).x; m_MoveDir.z = Vector2.ClampMagnitude(new Vector2(m_MoveDir.x, m_MoveDir.z), m_RunSpeed).y;

And the X value was different when the Z value was calculating.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Mouse-following script freezes Unity. 1 Answer

Can someone help me to understand what vector3.lerp does and can be used for 2 Answers

problem Changing Scales in Script -C# 4 Answers

Cannot modify a value type return value of `UnityEngine.Transform.position'. Can anyone help ? 1 Answer

Problems with Vector3.angle and angle to target 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