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 MartinTV · Mar 18, 2016 at 05:57 AM · vector3transformdirection

TransformDirection causing move Jitter

So here is the deal, I am moving the player with different control schemes while on the ground and in the air. On the ground the player's velocity (using a Rigibody BTW) is simply being set to the desired velocity, while in the air I slowly increase/decrease the values of the vector i am moving across so the player has less control in the air.

I am then making the movement relative to the player's forward direction

What I get is that it works perfectly while the player is facing forward with the world. The moment that changes, his ground movement is still working as intended but the air movement makes him jitter and not move in the desired direction at all.

When I take the transformdirection line out, it works but the character's movement is relative to the world.

I imagine it is because of how I am changing the vector while in the air. It is the only thing that I can think of at least.

     //Movement
     public float speed = 10f;
     public float airSpeed = 2.5f;
     Vector3 moveDir = new Vector3();
     // Jumping
     public bool isGrounded = true;
     Ray groundRay = new Ray();
     RaycastHit groundHit;
     public float rayDist;
     public float jumpForce;
     // Components
     Rigidbody RB;
 
     void Start ()
     {
         // Find/Get components
         if(this.GetComponent<Rigidbody>())
             RB = this.GetComponent<Rigidbody>();
         else
             RB = this.gameObject.AddComponent<Rigidbody>();
     }
     
     // Update is called once per frame
     void Update ()
     {
     //---------------Movement
         if(isGrounded)
         {
             moveDir.x = Input.GetAxis("Horizontal") * speed;
             moveDir.z = Input.GetAxis("Vertical") * speed;                
         }
         else
         {
             moveDir.x += (Input.GetAxis("Horizontal") * airSpeed) * Time.deltaTime;
             moveDir.z += (Input.GetAxis("Vertical") * airSpeed) * Time.deltaTime;
         }
         // Gravity
         moveDir.y = RB.velocity.y;
         moveDir = transform.TransformDirection(moveDir);
     //-----------Jumping 
         // Ground Check
         groundRay.origin = this.transform.position;
         groundRay.direction = Vector3.down;
         isGrounded = Physics.Raycast(groundRay, out groundHit, rayDist);
 
         if(Input.GetKeyDown("space"))
             moveDir.y = jumpForce;
     }
 
     void FixedUpdate()
     {
         RB.velocity = moveDir;
     }


So what gives? I have no idea why adding to the vector3's XY values with deltaTime should make this behaviour.

Thanks in advance for help.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by MartinTV · Mar 20, 2016 at 02:32 AM

If I didn't explain things well enough, just throw this puppy onto an object and you'll see what I mean

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 lukebb0215 · Jan 17, 2020 at 11:02 PM

Try only using Transform.TransformDirection when the player is grounded. I had a similar issue and this fixed the problem for me

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

43 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

Related Questions

Movement relative to Camera and XZ Plane 1 Answer

How to transform local space to world GYRO space on ios? 0 Answers

Gyroscope.attitude = GetComponent ().TransformDirection ? 1 Answer

Unit Formation Aligns to a Reset Forward Position Rather Than Parent Object's Rotation 1 Answer

Lerp jump using input won't convert to world space 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