Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 minavazatoka · Apr 10 at 05:05 PM · unity 2djump

My player does not jump on every click and if it jumps it is really short

Hello all, for some reason when I press spacebar and I try to jump, my player does not always jumps. Also when it does jump it kinda teleports to some point on the screen and then quickly falls down as if something really heavy pulls it down. This is my script, it is really simple: using System.Collections; using System.Collections.Generic; using UnityEngine;

 public class PlayerMovement : MonoBehaviour
 {
     public Rigidbody2D Player;
     public float movementSpeed;
     public float jumpHeight;
     // Start is called before the first frame update
     void Start()
     {
         
     }
 
     // Update is called once per frame
     void Update()
     {
         Player.velocity = new Vector2(movementSpeed * Input.GetAxis("Horizontal"), Player.position.y);
         if (Input.GetButtonDown("Jump"))
         {
             Player.velocity = new Vector2(Player.position.x, jumpHeight);
         }
     }
 }
 

My components that I have on the player: alt text

I will be gratefull for any help. I really do not know why this is happening. If you want a demo of what is happening, I am willing to provide a video. I looked at other answers here, but they were about using FixedUpdate and I do not use it as you can see.

jumpproblem.png (43.1 kB)
Comment
Add comment · Show 2
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 divinereignoflords · Apr 10 at 05:56 PM 0
Share

What's your gravity set to? also, try using transform, ie Player.transform.position.x as it seems you just setting a location for it to appear when the spacebar is pressed.

avatar image minavazatoka divinereignoflords · Apr 10 at 06:08 PM 0
Share

I needed to use velocity and I just did not saw this mistake in my code. Thank you for the suggestion. :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by minavazatoka · Apr 10 at 06:07 PM

I am sorry all, the bug in the code was that I was using:

 Player.velocity = new Vector2(Player.position.x, jumpHeight);

Instead of this I had to use:

 Player.velocity = new Vector2(Player.velocity.x, jumpHeight);

I think as divinereignoflords said I was setting new location for the object to appear to with the position property.

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

146 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

Related Questions

Exponential Increase/Decrease jump 3 Answers

my jump key works about once every 10 presses 1 Answer

I really need a JumpPad script for a JumpPad in unity 2D 0 Answers

How do I fix this stupid jump animation not transitioning 1 Answer

JumpPad script for a JumpPad like Geometery dash 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