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 benandlucy · Jan 05, 2014 at 09:21 PM · rigidbody2dvelocityjump

rigidbody2d.velocity isn't doing anything.

Hello, my character is supposed to be able to jump with a rigidbody.velocity script. I have a rigidbody component for character, but it still won't do anything. Also the console shows no errors. What is wrong?

//jumping

  if(canJump == true){
 rigidbody2D.velocity.y =10;
 Debug.Log("This Shows up")
 

 }
 }
 
 
 
  function OnCollisionStay2D(coll: Collision2D) {
      
      if(coll.gameObject.tag == "Terrain" && Input.GetKeyDown(KeyCode.W)){
  canJump = true;
      
  
  }
  else{
      canJump = false;
  }
  }


I'm pressing "w" , and the log shows up, but my character does not jump. Please help, this has been stumping me for the past few days.

UPDATE UPDATE

The programming part look's like it has no problems. Here's my project so you can see.

https://www.mediafire.com/?ro0rmr0lx28epgo

A and D - left/right W - Should make you jump if we get the problem figured out.

Yeah, and I know it's simple. Just testing out things really.

Thank you.

Comment
Add comment · Show 8
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 ncallaway · Jan 06, 2014 at 01:02 AM 0
Share

Would you be able to provide a sample project that shows this problem? From the code you posted it looks like it should work.

avatar image Invertex · Jan 06, 2014 at 01:16 AM 0
Share

Use rigidbody2D.AddForce ins$$anonymous$$d.

 function OnCollisionStay2D(coll: Collision2D) 
 {
 
 if ((coll.gameObject.tag == "Terrain") && (Input.Get$$anonymous$$eyDown("w")))
 {
 rigidbody2D.AddForce(new Vector2(0,100));
 }
 
 }

Simplified the code too. No need to be swapping around a bool, when you already check to see if the person is on terrain. If they are pressing "w" while they are colliding with the ground, then you make them jump. No bool needed.

avatar image benandlucy Invertex · Jan 06, 2014 at 01:32 AM 0
Share

Thanks for the simplified version, BUT addforce isnt see$$anonymous$$g to do anything either. I'm going to upload my project to my question, as this doesn't seem to be a program$$anonymous$$g issue.

avatar image Invertex Invertex · Jan 06, 2014 at 01:55 AM 0
Share

Try adding a Debug log to the on collision function to see if it's even being triggered at all.

avatar image benandlucy Invertex · Jan 06, 2014 at 02:00 AM 0
Share

Yes, it does get called.

Show more comments
avatar image benandlucy · Jan 06, 2014 at 01:48 AM 0
Share

Added my project :)

2 Replies

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

Answer by ncallaway · Jan 06, 2014 at 02:14 AM

The problem is that Turtle has an Animator on it with "Apply Root Motion" checked. This means the Animator is constantly updating the position of the turtle to be in a position as defined by the animation it's playing.

If you uncheck Apply Root Motion from the Animator, your jump code starts working.

I also used rigidbody2d.velocity.y = 10 instead of rigidbody2d.AddForce().

I also found that "Gravity Scale" on the Turtle's rigidbody was quite strong, so that the Turtle wasn't able to jump very high, so you'll probably want to play with that number a bit.

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 benandlucy · Jan 06, 2014 at 02:19 AM 2
Share

Oh my! Thank you so much. I thought it was something small that was in the way. Have a good one!

avatar image MikePatterson · Feb 01, 2014 at 04:12 AM 0
Share

Holy crap ncallaway, thank you so much, I've been $$anonymous$$ring my hair out trying to figure out why rigidbody2D.AddForce() AND rigidbody2D.velocity hasn't been working! Thankyouthankyouthankyouthankyouthankyouthankyou

avatar image
0

Answer by superluigi · Jan 06, 2014 at 01:37 AM

This might sound a little crazy but try

 function OnCollisionStay2D(coll: Collision2D) 
 {
      if(coll.gameObject.tag == "Terrain" && Input.GetKeyDown(KeyCode.W))
      {
           canJump = true;
           rigidbody2D.velocity.y =10;
      }
 }

Let me know if you get something. Also if you don't mind post your entire code.

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 benandlucy · Jan 06, 2014 at 01:49 AM 0
Share

I posted my whole entire project so the whole script is in there. Thank you for trying to help.

avatar image superluigi · Jan 06, 2014 at 01:59 AM 0
Share

Ok but did u try m suggestion? I think it is a problem with ur code and that it'll work.

avatar image benandlucy · Jan 06, 2014 at 02:07 AM 0
Share

I tried it, but no, it didn't work.

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

22 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

Related Questions

rigidbody2D : X velocity is slowed down when I jump. 1 Answer

Convert Force into Velocity for 2D Player Jump 0 Answers

Horizontal/Parabolic Projectil Movement and Jump for 2D //HELP! 0 Answers

Velocity not updating object position 1 Answer

How to get a rigidbody2d's actual speed? 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