Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Eucalyptus · Nov 02, 2014 at 08:18 PM · rigidbody2daddforce

Problems with rigidbody2D.AddForce

Hi! , Im trying to get jumps like the game "the impossible game": https://www.youtube.com/watch?v=vW8nXTzroos

Well, I wrote the essential, some rigidbody2D.AddForce to make the jump etc, the PROBLEM is that when I click ( It add the force in Y) it add more force to X, and obviously I don't want that, I want to keep the velocity in the X.

And sorry for my english ^^ Ohh and if someone knows how to do these types of jumps like the video I posted, tell me please! I tried to change the gravity but I still without get this type of jumps hehe.

Here is the code, hope you can help me guys!:

 using UnityEngine;
 using System.Collections;
 
 public class controladorPersonaje : MonoBehaviour {
 
     public float fuerzaSalto = 100f;
     public float fuerzaCorrer = 100f;
 
     public bool enSuelo = true;
     public bool enSuelo1 = true;
     public bool enSuelo2 = true;
     public bool enSuelo3 = true;
     public bool enSuelo4 = true;
 
 
     
 
     public Transform comprobadorSuelo;
     float comprobadorRadio = 0.07f;
     public Transform comprobadorSuelo1;
     float comprobadorRadio1 = 0.07f;
     public Transform comprobadorSuelo2;
     float comprobadorRadio2 = 0.07f;
     public Transform comprobadorSuelo3;
     float comprobadorRadio3= 0.07f;
     public Transform comprobadorSuelo4;
     float comprobadorRadio4 = 0.07f;
     public LayerMask mascaraSuelo;
     private Animator animator;
 
     void Awake(){
         animator = GetComponent<Animator> ();
         }
 
     // Use this for initialization
     void Start () {
 
     }
 
     void FixedUpdate(){
 
 
                 enSuelo = Physics2D.OverlapCircle (comprobadorSuelo.position, comprobadorRadio, mascaraSuelo);
                 animator.SetBool ("isGrounded", enSuelo);
 
         enSuelo1 = Physics2D.OverlapCircle (comprobadorSuelo1.position, comprobadorRadio1, mascaraSuelo);
         animator.SetBool ("isGrounded", enSuelo1);
         
         
         enSuelo2 = Physics2D.OverlapCircle (comprobadorSuelo2.position, comprobadorRadio2, mascaraSuelo);
         animator.SetBool ("isGrounded", enSuelo2);
         
         enSuelo3 = Physics2D.OverlapCircle (comprobadorSuelo3.position, comprobadorRadio3, mascaraSuelo);
         animator.SetBool ("isGrounded", enSuelo3);
         
         enSuelo4 = Physics2D.OverlapCircle (comprobadorSuelo4.position, comprobadorRadio4, mascaraSuelo);
         animator.SetBool ("isGrounded", enSuelo4);
 
         rigidbody2D.AddForce (new Vector2 (fuerzaCorrer, 0));
 
         if (enSuelo && Input.GetMouseButton (0) || enSuelo1 && Input.GetMouseButton (0)|| enSuelo2 && Input.GetMouseButton (0)|| enSuelo3 && Input.GetMouseButton (0)|| enSuelo4  && Input.GetMouseButton (0)) {
 
 
             rigidbody2D.AddForce (new Vector2 (0, fuerzaSalto));
             //transform.Rotate(new Vector3(0,0,70));
             //transform.Rotate(0, Time.deltaTime * 30, 0, Space.Self);
 
 
                 }
 
         }
     // Update is called once per frame
 
 
 
     void Update () 
     {
 
     }
         
 
 }

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 AlwaysSunny · Nov 02, 2014 at 07:33 PM 0
Share

I don't see the problem. You're adding fuerzaCorrer force on X each frame, and fuerzaSalto force on Y when you jump. What exactly do you want to do differently?

avatar image Eucalyptus · Nov 02, 2014 at 07:59 PM 0
Share

Yes, but when I jump it add more force on X, I mean the square goes more faster on X than if I dont jump

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by AlwaysSunny · Nov 02, 2014 at 08:16 PM

Oh, I get it. You're probably experiencing drag due to friction when your object is grounded. There are various ways to address this problem, and selecting the appropriate method depends on your preference for how the object should behave.

Since you want to move with the same X velocity at all times, the easiest way is probably giving the object a physics material with zero friction. Also, to maintain this same-X-velocity rule, you might consider setting the rigidbody's "drag" property to zero as well.

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 Eucalyptus · Nov 02, 2014 at 09:53 PM 0
Share

$$anonymous$$en, I don't know what to say, thanks isn't enough, seriously you made me happy this day, THAN$$anonymous$$S for all seriously and with that I got the jumps that I wanted like in the game :) Thanks!!!!

Sorry for my english :P

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Rigidbody2D AddForce only working with large numbers 2 Answers

Jump problem 1 Answer

Unity 2D Physics .AddForce 1 Answer

Can someone help me with this Rigidbody2D bug? 1 Answer

Character instantly jumps instead of smoothly gaining altitude 3 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