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 Den D. · Dec 05, 2014 at 03:04 PM · physicsforwardridgidbody

Player does not Jump Issue(Unity3D)

This is my first character control script.

the cube should be able to jump (failed)

I want to make the cube jump but it just sticks to the ground. When gravity is turn on it jump but does not move forward and when gravity is turn off it moves forward but when pressed Jump it does not come down continuously move up.

  void FixedUpdate ()
     {
   
         Vector3 vel = rigidbody.velocity;
         vel.x = Input.GetAxisRaw("Horizontal") * MaxHorSpeed;
 
         if (Input.GetKeyDown(KeyCode.Space) && IsGrounded()){
             vel.y = jumpSpeed;

         }
  }



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
Best Answer

Answer by Lunatix · Dec 05, 2014 at 03:16 PM

Your player might not move because of surface friction.

Try to use the following code snippet to move your character:

 var movement = Vector3.forward * movementFactor * Time.deltaTime;
 var desiredPosition = gameObject.position + movement;
 
 rigidBody.MovePosition(desiredPosition);

I also would suggest to use some lerping to smooth the start end end of movement motion.

Comment
Add comment · Show 3 · 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 Lunatix · Dec 05, 2014 at 03:39 PM 0
Share

Brief description from docs: "Use $$anonymous$$ovePosition to prevent rigidBodies from teleporting". This method will "step" your rigidBody to the desired position and takes care of collisions.

http://docs.unity3d.com/ScriptReference/Rigidbody.$$anonymous$$ovePosition.html

avatar image Den D. · Dec 06, 2014 at 01:38 AM 0
Share

thanks all lot for the documentation but it does have a problem with colliders its works well when speed of player is slow but when the speed is increased the player passes through the collider ignoring it and also my player is type of a car and using $$anonymous$$ovePosition gives a sudden movement in forward direction where as addforce slowly and gradually increases the speed of the vehicle.

avatar image Lunatix · Dec 06, 2014 at 11:01 AM 0
Share

Why didn't you mention that the player drives car before? $$anonymous$$aybe you should update your question.

$$anonymous$$aybe the air friction is set much to high, also, it is not always recommended to use velocitiy directly (in your code, the velocity is taken before addforce is called!) and why the clamping?

Ins$$anonymous$$d of clamping, just stop adding force when the velocity is big enough. One more hint: velocity is applied in the direction you are heading, setting "y" directly can lead to wrong movement.

For example, if you want to push another character, one can calculate the "push" direction by using: character.transform.rotation * Vector3.forward * throwBackAmount;

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

26 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

Related Questions

Adding force to forward direction 1 Answer

(C#) How would I go about making physics like F-Zero GX's? 1 Answer

fast forward physic vehicles 0 Answers

Tearing Polygon as if Paper? 1 Answer

2D 360 degress platformer example needed 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