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 loony220792 · Jun 29, 2018 at 11:21 AM · jumpaddforcemarioholding

Mario jump addforce problem

Hi, I need help with jumping like a mario. I found this solution on the Internet, but I don't like the physics of the jump because of the velocity. When changing to addforce, only a short jump works, as it is not respected (rb.velocity.y> jumpMinForce). I can not understand what condition to ask and what to change, so that everything works with Addforce. Thank you

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class BetterJump_2 : MonoBehaviour {
 public float jumpMinForce = 3f;   
 public float jumpForce = 10f;         
 bool jump = false;
 bool jumpCancel = false;
 public LayerMask whatIsGround;
 private bool isGrounded = false;
 public Transform groundCheck;
 private float groundRadius = 0.2f;
 private Rigidbody2D rb;
 
 void Awake (){
     rb = GetComponent<Rigidbody2D>();
 }
 void Update()
 {
     isGrounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
     // Check ground
     
     if (Input.GetButtonDown("Jump") && isGrounded)   // Start Press Jump
         jump = true;
     if (Input.GetButtonUp("Jump") && !isGrounded)     // Stop Press Jump
         jumpCancel = true;
 }
 
 void FixedUpdate()
 {
     // Simple Jump
     if (jump)
     {
         rb.AddForce(Vector2.up*jumpForce, ForceMode2D.Impulse);
 //        rb.velocity = new Vector2(rb.velocity.x, jumpForce);
         jump = false;
     }
     // Cancel Jump
     if (jumpCancel)
     {
         if (rb.velocity.y > jumpMinForce)
 //      rb.velocity = new Vector2(rb.velocity.x, jumpMinForce);
         rb.AddForce(Vector2.up*jumpMinForce, ForceMode2D.Impulse);
         jumpCancel = false;
     }
     }
 }
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

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

148 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

Related Questions

rigidBody.addforce doens't work like i want it to 1 Answer

Input.GetButtonDown("Jump") doesn't work 0 Answers

rigidbody2D addforce on x-axis 1 Answer

Unity 5: AddForce Increases power when already being pushed towards a collider. How to make stop? 1 Answer

super mario bros 3 sytle 3D platformer engine 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