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 Makiavel · Aug 26, 2015 at 11:21 AM · movementjumpcontrolaccelerationfirst person controller

Disable movement control during jump

I want to make my character unable to change his movement direction while not connected to the ground (or a wall for that matter). In old unity I could simply disable the .canControl of CharacterMotor and enable it again when the character comes close enough to a surface. Is it possible to achieve the same effect in the new first person controller? I tried to simply equate the input on both axes to 0, but that stops character dead in his tracks the moment he jumps.

Simply put: I want to disable control but keep the momentum and acceleration. Is it possible to achieve that without writing a completely new first person controller?

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 Scibbie · Jan 11, 2016 at 03:25 PM 0
Share

@$$anonymous$$akiavel I used a Bool variable that would go like this: If you were not in contact with the ground, go to false. if in contact go to true.

And then in Update/FixedUpdate class if the boolean is true, do everything below (all moving controls).

BUT: The true/false method works, I can put the bool on true, $$anonymous$$oves, and false, Cant controll my object. But my Collision check if im in contact with ground. Doesnt work. Tell me if you got a way to check for collision with ground. Because it doesnt switch automatically for me. (Probably something I did wrong)

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by fabian0010k · May 26, 2016 at 09:44 PM

Found a solution (if you are using the FPS controller): In your FirstPersonController change line 219 from

 m_Input = new Vector2(horizontal, vertical);

to

 if(!m_Jumping)
     m_Input = new Vector2(horizontal, vertical);
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 ttesla · Apr 14, 2019 at 05:52 PM

I modified standard FPS controller FixedUpdate a little bit to limit air control.

  private Vector3 mLastDesiredMove;
  private float mLastSpeed;
 
  private void FixedUpdate()
  {
      float speed;
      GetInput(out speed);
      // 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, Physics.AllLayers, QueryTriggerInteraction.Ignore);
      desiredMove = Vector3.ProjectOnPlane(desiredMove, hitInfo.normal).normalized;

      // On air limit
      if (m_CharacterController.isGrounded)
      {
          mLastDesiredMove = desiredMove;
          mLastSpeed = speed;
      }
      else
      {
          desiredMove = mLastDesiredMove + desiredMove * 0.25f;
          speed       = mLastSpeed;
      }
 
      m_MoveDir.x = desiredMove.x*speed;
      m_MoveDir.z = desiredMove.z*speed;
 
      if (m_CharacterController.isGrounded)
      {
           m_MoveDir.y = -m_StickToGroundForce;
 
           if (m_Jump)
           {
                m_MoveDir.y = m_JumpSpeed;
                PlayJumpSound();
                m_Jump = false;
                m_Jumping = true;
           }
     }
     else
     {
         m_MoveDir += Physics.gravity*m_GravityMultiplier*Time.fixedDeltaTime;
      }
      m_CollisionFlags = m_CharacterController.Move(m_MoveDir*Time.fixedDeltaTime);
 
      ProgressStepCycle(speed);
      UpdateCameraPosition(speed);
 
      m_MouseLook.UpdateCursorLock();
 }
 


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

28 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

Related Questions

How to make camera position relative to a specific target. 1 Answer

About in air control 2 Answers

Trying to get accelerated jump speed. 2 Answers

In air movement troubles. 1 Answer

tilt control for jump 0 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