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 xW1Zx · Feb 06, 2020 at 04:41 PM · movementjumpaddforce

AddForce Jump Doesn't Work

Hello , I don't know why Jump don't work // im new in unity so i need some help Note : walk is good!!

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlayerController : MonoBehaviour
 {
     CharacterController controller;
 
     private Rigidbody rb;
     private Animator playeranim;
     public float speed = 18.0f;
     public float gravity = -12f;
     public float jump = 15f;
     private float verticalVelocity;
     public bool IsOnGround = true;
 
     Vector3 movedirection = Vector3.zero;
     
      
     // Start is called before the first frame update
     void Start()
     {
         rb = GetComponent<Rigidbody>();
         playeranim = GetComponent<Animator>();
         controller = GetComponent<CharacterController>();
          
     }
 
     // Update is called once per frame
     void Update()
     {
 
 
         Jump();
         walk();
    
     }
 
 
  
 
     void walk()
     {
  
 
         float leftrightzft = Input.GetAxis("Horizontal") * 3f;
 
 
 
 
         if (IsOnGround == true)
         {
  
             movedirection = new Vector3(leftrightzft, 0, 2f);
             movedirection *= speed;
         }
  
              
             controller.Move(movedirection * Time.deltaTime);
  
     }
 
     void Jump()
     {
         if (IsOnGround&&Input.GetKeyDown(KeyCode.Space))
         {
             rb.AddForce(Vector3.up * jump, ForceMode.Impulse);
         }
 
     }
 
     private void OnCollisionEnter(Collision collision)
     {
         if (collision.gameObject.CompareTag("Ground"))
         {
             IsOnGround = true;
         }
 
     }
 
 
 }
  

Comment
Add comment · Show 3
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 AppuViradiya · Feb 06, 2020 at 04:53 PM 0
Share

You should add rigidbody component Or Any Rigidbody constraints is marked

avatar image AppuViradiya · Feb 06, 2020 at 04:53 PM 0
Share

@xW1Zx .....

avatar image xW1Zx AppuViradiya · Feb 06, 2020 at 05:04 PM 0
Share

I know I have Rigibody already

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by unity_ek98vnTRplGj8Q · Feb 06, 2020 at 05:09 PM

Do not use both a character controller AND a rigidbody on the same object. Choose one and stick to it. Also, the reason that your jump doesn't work is because you have isKinematic checked on your rigidbody. Your character can be controlled directly or by physics but not by both at the same time. You likely want to control your character directly, (controlling your character by adding forces is much harder and offers less control). If you want to "Add a force" to a kinematic rigidbody or a character controller, you have to simulate this yourself by keeping track of the velocity of the character, and then moving it by that velocity every frame.

 public float jumpStrength;
 
 private Vector3 _velocity;
 private float velocityBleedSpeed = 2f;
 
 void Update(){
     Jump();
     controller.Move(_velocity * Time.deltaTime);
     _velocity = Vector3.Lerp(_velocity, Vector3.zero, velocityBleedSpeed*Time.deltaTime);
 }
 
 void Jump(){
     if(IsOnGround && Input.GetKeyDown(KeyCode.Space)){
         _velocity += new Vector3(0,jumpStrength, 0);
     }
 }
 
 


Comment
Add comment · Show 4 · 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 xW1Zx · Feb 06, 2020 at 05:27 PM 0
Share

It's Work very thanks x 1241431 You don't know how tired I am because of this thing , but i want to use gravity 2 !

avatar image unity_ek98vnTRplGj8Q xW1Zx · Feb 06, 2020 at 05:31 PM 0
Share

$$anonymous$$ake your own gravity ;)

  public float jumpStrength;
  
  private Vector3 _velocity;
  private float gravity = 9.81f;
  private float velocityBleedSpeed = 2f;
  
  void Update(){
      Jump();
      controller.$$anonymous$$ove(_velocity * Time.deltaTime);
      if (!IsOnGround) _velocity.y -= gravity * Time.deltaTime;
      _velocity = Vector3.Lerp(_velocity, Vector3.zero, velocityBleedSpeed*Time.deltaTime);
  }
  
  void Jump(){
      if(IsOnGround && Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space)){
          _velocity += new Vector3(0,jumpStrength, 0);
          IsOnGround = false;
      }
  }

avatar image xW1Zx unity_ek98vnTRplGj8Q · Feb 06, 2020 at 05:39 PM 0
Share

very thanks man,I lost two days of my time because of this thing !! and thanks lol.

Show more comments

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

181 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

AddForce Movement Constraint 0 Answers

AddForce to Camera 1 Answer

moving with rigidbody without acceleration 0 Answers

Player appears to teleport instead of adding force 2 Answers

My movement function with jump won't work with collider function 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