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 vivekkalkur · Jul 08, 2013 at 09:49 AM · gameobjectrigidbodyvelocity

Why is my rigidbody.velocity not working?

Hi Unity devs,

I am having a GameObject with a sprite script added to it. I have attached a boxcollider and a rigidbody as well to that object and I am trying to execute this:

  void Update() {
  float jumpspeed = 8.0f;
    if (Input.GetKeyDown (KeyCode.Space))
      {
        rigidbody.velocity += jumpspeed * Vector3.up;
 
      } 
  }

This script is attached to the current gameobject.

Here nothing seems to be happening when I press spacebar.

Why is that so?

Comment
Add comment · Show 1
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 gamerant · Jul 08, 2013 at 10:48 AM 0
Share

I'm not an expert coder so I can't say why this isn't working exactly but I think you are trying to add a velocity to your rigid body ins$$anonymous$$d of force.Think of it this way.You can't move any object in real life by simply adding velocity to it.Physics doesn't work that way.In order to have velocity you must give the object a push or have a force acting on it.Like giving a ball a kick.You add a force to the ball by kicking which then causes the ball to move with a certain velocity. I'd say try to add this ins$$anonymous$$d inside your if statement rigidbody.AddForce(0,jumpSpeed,0);. This will simply add a force to your object along the y axis.You will need to add some logic to prevent the player from jumping mid air or multiple times in a row though. Also try changing jumpspeed to jumpSpeed .It's a small change but allows for an easier read of the code for everyone :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by diogomota · Jul 08, 2013 at 10:55 AM

that code is working fine here, maybe you are using a different up vector.. try with other vector3 directions.

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

17 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

Related Questions

How to make gameobjects fall down faster with each update ? 1 Answer

C # Applying Velocity to Rigidbody 1 Answer

Rigidbody Disable Velocity/Movement? 1 Answer

Velocity powered rigidbody on a moving platform without parenting. 3 Answers

Dragging object out of position 2 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