• 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 andras02 · Oct 30, 2018 at 12:22 PM · scripting problemjumpbug-perhaps

I use this code to jump, but it's just teleporting my player upwards. It works totally perfect in an other project.

public class Jump : MonoBehaviour {

 public float JumpForce = 150f;
 Rigidbody2D rb;

 
 void Start () {
     rb = GetComponent<Rigidbody2D>();
 }
 
 
 void FixedUpdate () {
     if (Input.GetButtonDown("Jump"))
     {
         rb.AddForce(Vector2.up * JumpForce * Time.deltaTime);
     }
 }

}

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
0

Answer by CDAXRC · Oct 30, 2018 at 02:59 PM

Remove * Time.deltaTime

Comment
Add comment · Show 1 · 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 andras02 · Oct 30, 2018 at 03:42 PM 0
Share

I tryed it, but it also doesn't working.

avatar image
0

Answer by hameed-ullah-jan · Oct 30, 2018 at 04:33 PM

Try this thing hope it will work:

if(Input.GetKeyDown(KeyCode.Space) && isGrounded) {
rb.AddForce(jump * jumpForce, ForceMode.Impulse); isGrounded = false; }

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 andras02 · Oct 30, 2018 at 09:30 PM 0
Share

It's also doesn't work.

avatar image hameed-ullah-jan · Oct 31, 2018 at 06:20 AM 0
Share

check your gravity, are you sure that gravity is on?

avatar image
0

Answer by The_Phantom16 · Oct 30, 2018 at 10:47 PM

Um...let me see if I can try to help.

1) Created a small project for this. Here is my setup in the editor (just in case the issue is not in the code): alt text

2) Programming wise, I just copied and pasted your code. Got rid of the Time.deltatime because you already have the jump code in the FixedUpdate() (also it causes the object have really really tiny jumps):

alt text

3) I ran the project, pressed the space bar and it works for me.

Hope this helps you out! :D


capture1.jpg (449.0 kB)
capture2.jpg (47.5 kB)
Comment
Add comment · Show 1 · 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 andras02 · Oct 31, 2018 at 08:11 AM 0
Share

Thank you, it not helps a lot becouse I alredy knew it, but I'll remove the Time.deltaTime.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

172 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

Related Questions

Confused as to why he only jumps while walking? 1 Answer

Make a Jump Delay 1 Answer

Why can't my character jump 2 Answers

1 out of 4 objects with the same script that reference the same transform list returning null? 1 Answer

Exiting an if statement when calling a function from another script (Possible bug) 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges