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
-1
Question by Collects · Dec 30, 2018 at 08:38 PM · jumpforce

My code isn't working

I have a game, that you have to dodge blocks, and I am implementing a jump feature.

I have the code

public float upwardForce = 100;

If (Input.GetKey(“up”)) { rb.AddForce(0, 0, upwardForce * Time.DeltaTime); }

It doesn't work, and I can't publish the game until it does. I also want to make it so they will fall back to earth and they can't use it when they are in the air. Thanks. Can someone please help me?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by sean244 · Dec 30, 2018 at 08:52 PM

Try this

 using UnityEngine;

 public class Player : MonoBehaviour
 {

 private Rigidbody2D rb;
 private bool jumping;
 public float upwardForce = 3f;


 void Start()
 {
     rb = GetComponent<Rigidbody2D>();
 }

 private void Update()
 {
     if (Input.GetButtonDown("Jump"))
         jumping = true;
 }

 private void FixedUpdate()
 {
     if (jumping)
     {
         jumping = false;
         rb.AddForce(Vector2.up * upwardForce, ForceMode2D.Impulse);
     }
 }
 }
Comment
Add comment · Show 6 · 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 Collects · Dec 30, 2018 at 08:53 PM 0
Share

Thanks, I will try this out!

avatar image Collects · Dec 30, 2018 at 09:04 PM 0
Share

This worked so well! Now is there a way to make it so he can only jump when on the ground and not when in the air.

avatar image sean244 Collects · Dec 30, 2018 at 09:06 PM 0
Share

Do you have a bool that returns if the player is grounded or not?

avatar image Collects sean244 · Dec 30, 2018 at 09:07 PM 0
Share

I am not that good at Unity. So I don't. I'm sorry

Show more comments
avatar image
-1

Answer by giveson · Dec 30, 2018 at 08:47 PM

At the end of the code where it says if (jumping) it should say if (jumping == true) if not it might be if (jumping = true)

Comment
Add comment · Show 2 · 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 Collects · Dec 30, 2018 at 08:49 PM 0
Share

That is alright. It is a 3d game.

avatar image sean244 · Dec 30, 2018 at 09:18 PM 0
Share

No, if(jumping) is identical to if (jumping == true).

avatar image
-1

Answer by Collects · Jan 10, 2019 at 12:49 PM

I'm back. I couldn't figure it out, If any has any other answers I would love it!

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

102 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

Related Questions

AddForce jump height dimities on level reload,Add force Jump height diminishes on every level reload. 1 Answer

How to make Sphere to jump? 2 Answers

How to make a jump script which controlled force 1 Answer

Change rigidbody's jumping speed 2 Answers

Jumping increases movement speed 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