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 /
  • Help Room /
avatar image
0
Question by TheFish657 · Mar 26, 2016 at 01:42 PM · rigidbody 2d

Add Force not working

I have a first person character which i want to make jump. I have a rigidbody and a character controller attached. The rigidbody is set to: Enable gravity - true, is keinematic - false and restrict x and z movement and all rotation. This is my code.

 [RequireComponent(typeof(CharacterController))]
 [RequireComponent(typeof(Rigidbody))]
 public class playerMove : MonoBehaviour {
     public float speed = 60.0F;
     public float sideSpeed = 40.0F;
     public float jumpForce = 80.0F;
     public float sensitivity = 30.0F;
     public float gravity = 20.0F;
 
     void Update() {
         Rigidbody rb = GetComponent<Rigidbody> ();
         CharacterController controller = GetComponent<CharacterController> ();
 
         Vector3 forward = transform.TransformDirection (Vector3.forward);
         Vector3 sideways = transform.TransformDirection (Vector3.right);
         Vector3 up = transform.up;
 
         float curSpeed = speed * Input.GetAxis ("Vertical") * Time.deltaTime;
         float curSideSpeed = sideSpeed * Input.GetAxis ("Horizontal") * Time.deltaTime;
         float rotation = Input.GetAxis ("Mouse X") * sensitivity * Time.deltaTime;
 
         controller.SimpleMove (forward * curSpeed);
         controller.SimpleMove (sideways * curSideSpeed);
         transform.Rotate (0, rotation, 0);
 
         if (Input.GetKeyDown(KeyCode.Space) && controller.isGrounded) {
             rb.AddForce(up * jumpForce);
             Debug.Log ("Adding Force");
         }
     }
 }

Any ideas why this is happening?

Comment
Add comment · Show 5
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 AUNaseef · Mar 26, 2016 at 02:03 PM 0
Share

What is the mass of Rigid Body? Your script doesn't work if mass is set to more than '2'.

  1. Try increasing value of jumpForce.

  2. $$anonymous$$ake sure controller.isGrounded returns true.

  3. $$anonymous$$ake sure 'Freeze Position Y' is false.

avatar image ItTookMe2MonthsToCreateAnAccountHereSuccessfully · Mar 26, 2016 at 02:04 PM 1
Share

"Add force not working" - What is not working? Is it the wrong direction? Is the force too small?

"Enable gravity - true, is keinematic - false and restrict x and z movement and all rotation" - Does this mean you set the restrictions of all movement axis and rotation axis to true? Then it can't move.

Are you sure the CharacterController.isGrounded is true? Does it print the log line?

You need to be clear where you have a problem.

avatar image AUNaseef · Mar 26, 2016 at 02:07 PM 0
Share

Question by TheFish657 · 22 $$anonymous$$utes ago · rigidbody 2d Add Force not working

Is it was 'Rigidbody 2D' or 'Rigidbody'?

avatar image TheFish657 · Mar 26, 2016 at 02:09 PM 0
Share

it was a regular rigidbody. The debug line prints. isGrounded is set to true. Y axis movement is not restricted. The mass is 1. When i increase jumpforce nothing changes.

avatar image Owen-Reynolds · Mar 26, 2016 at 02:36 PM 0
Share

CharacterControllers and rigidbodies are usually one or the other -- they tend not to work well together. $$anonymous$$ost CC's jump by manually setting a y-speed for simple$$anonymous$$ove. I can see the idea of limiting the RB to y-only, but still don't trust them together.

I'm also not sure about several simple$$anonymous$$oves in a row. Seems better to combine into one (not sure, but flags may be set by the last one only.)

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

40 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

Related Questions

Determining the torque required for Rigidbody2D.AddTorque given initial and final angle, revolutions and time 0 Answers

Change game object to rigidbody using code 2 Answers

My player's rigidbody 2d is being continuously pushed downwards by box collider 2d 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