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 Veerababu.g · Dec 18, 2015 at 07:38 AM · physics2djumping

how to jump to desired distance.

i need to do jumping my player to the fixed target position.i did it position.that's why it is not good to see .he is not jumping smoothly.I want to jump my player with physics.so it will looking good. and also the player has to reach the target with parabola shape.

i forgot to mention it's 2d game.the player is contentious jumping person.just like in #Give_it_Up game.

how can i do it .........help me out ........

thank you

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

2 Replies

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

Answer by Salanyel · Dec 18, 2015 at 08:39 AM

The solution I'd recommend to you is by using the physics engine of Unity. It will cost you a lot of test to adjust to the correct behaviour you're looking for, but when you'll have finished, it will be cool.

Add a RigidBody2D and a boxcollider2D to your character. Don't set it in kinematics. When you jump, you will call the function (addForce) to make your player jump. You'll have a public vector and a public value to configure your jump. Here is the code :

EDIT : Correct version of the code

  public Vector2 m_jumpDirection; // You can choose the perfect angle
  public float m_force;             // You can choose the right strengh for the impulse
 
  private bool m_isPlayerGoingToRight = true;
 
  void Update()
  {
      if (Input.GetButton("Jump"))
      {
          jump();
      }
  }
 
  void jump()
  {
      Vector2 playerDirection;
 
      if (!m_isPlayerGoingToRight)
      {
          playerDirection = configureJumpDirection(-1);
      }
      else
      {
          playerDirection = configureJumpDirection(-1);
      }
 
      gameObject.GetComponent<Rigidbody2D>().AddForce(playerDirection * m_force, ForceMode2D.Impulse);
  }
 
  Vector2 configureJumpDirection(int m_direction)
  {
      return new Vector2(m_direction * m_jumpDirection.x, m_jumpDirection.y);
  }

I'm currently installing Unity 5.3, so I couldn't test my code. If there is something wrong, write it, then I will correct my code.

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 Veerababu.g · Dec 18, 2015 at 09:56 AM 0
Share

how to tag?

avatar image Salanyel Veerababu.g · Dec 18, 2015 at 09:59 AM 0
Share

At the end of a reply, there is a little blue hyperlink "Accept" with a "validate" sign.

avatar image
0

Answer by Veerababu.g · Dec 18, 2015 at 09:00 AM

it giving the error. can't multiply vector2 with vector2.

i.e playerDirection * m_jumpDirection

here it gives the error.

getComponent().AddForce(playerDirection m_jumpDirection m_force, ForceMode2D.Impulse);

Comment
Add comment · Show 3 · 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 Salanyel · Dec 18, 2015 at 09:11 AM 0
Share

Here is the correct version :

 public Vector2 m_jumpDirection; // You can choose the perfect angle
     public float m_force;             // You can choose the right strengh for the impulse
 
     private bool m_isPlayerGoingToRight = true;
 
     void Update()
     {
         if (Input.GetButton("Jump"))
         {
             jump();
         }
     }
 
     void jump()
     {
         Vector2 playerDirection;
 
         if (!m_isPlayerGoingToRight)
         {
             playerDirection = configureJumpDirection(-1);
         }
         else
         {
             playerDirection = configureJumpDirection(-1);
         }
 
         gameObject.GetComponent<Rigidbody2D>().AddForce(playerDirection * m_force, Force$$anonymous$$ode2D.Impulse);
     }
 
     Vector2 configureJumpDirection(int m_direction)
     {
         return new Vector2(m_direction * m_jumpDirection.x, m_jumpDirection.y);
     }

I tested it and it works. All you have to do is : - test to find the correct value ° for the m_jumdirection, try to use value between 0 and 1 ° for the m_force, you can use a high value - Write the script to update your m_isPlayerGoingToRight to set it

avatar image Veerababu.g · Dec 18, 2015 at 09:28 AM 0
Share

previous one is working . just using

vector2.scale(playerDirection * m_jumpDirection)

avatar image Salanyel Veerababu.g · Dec 18, 2015 at 09:33 AM 0
Share

Perfect. If it works, remember to tag your question as "Solved" ;)

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

33 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

Related Questions

Uneven Jump Heights 1 Answer

What is the additional code shall I write to limit the speed and the direction when jumping.(2D game) 0 Answers

How do you make a object move, and jump. Also how do you add physics and collision? 0 Answers

2D Top-Down Platforming like Mario and Luigi: Super Star Saga 1 Answer

how can i make my player jump to fixed position contenously 0 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