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 $$anonymous$$ · Sep 11, 2015 at 08:22 PM · c#movement script

What is wrong here?

I am trying to make a script to move a ball(the main character) and he moves to right and left without problems or errors, but dont jump. Here is the code:

 using UnityEngine;
 using System.Collections;
 
     public class MovementScript: MonoBehaviour {
         //Variables
     
         public GameObject player;
         public Rigidbody2D rb2d;
     
         public float velocity= 1;
         public float jumpForce= 3;
     
     
         // Use this for initialization
         void Start () {
             rb2d = GetComponent<Rigidbody2D>();
         }
         
         // Update is called once per frame
         void Update () {
     
         }
         void FixedUpdate(){
             Movement();
         }
     
         //Movement
         void Movement(){
             //Jump
             if(Input.GetKey("space")){
                 rb2d.AddForce(Vector2.up * jumpForce);
             }
             //Move to left
             if(Input.GetKey("a")){
                 rb2d.AddForce(Vector2.left * velocity);
             }
             //Move to right
             if(Input.GetKey("d")){
                 rb2d.AddForce(Vector2.right * velocity);
             }
         }
     }






Comment
Add comment · Show 5
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 Dave-Carlile · Sep 11, 2015 at 08:23 PM 2
Share

If you're jumping, don't you want to add the force pointing up ins$$anonymous$$d of down?

avatar image MegaChuck64 Dave-Carlile · Sep 12, 2015 at 04:05 AM 0
Share

i would say that is most definitely the problem

avatar image $$anonymous$$ · Sep 12, 2015 at 07:37 AM 0
Share

Sorry, but that's not the error because I've tried with Vector2.up and then tried to Vector2.down, and none of the both worked.

avatar image hexagonius · Sep 12, 2015 at 09:12 AM 0
Share

is the jumpForce 0 in the inspector?

avatar image $$anonymous$$ hexagonius · Sep 12, 2015 at 09:13 AM 0
Share

No, the jumpForce in the inspector is 2.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by robin-theilade · Sep 12, 2015 at 09:27 AM

You need to increase the jump force by factor 10 or more. Try setting it to 30. Your script works on my machine when the force is that great.

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

Answer by RoCkHeArTeD · Sep 12, 2015 at 05:57 PM

@mega_rodrigo In your RigidBody component, is your Kinemetic option unchecked? I'm guessing that could be the problem if it is checked.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Player sometimes don't stop moving when Key is release, and is properly installed in the fixedUpdate() 1 Answer

Switching lanes 1 Answer

Problem with unity grid step movement 0 Answers

How do i do tactical gridbased movement with movement points? 1 Answer

Disable movement button, C# 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