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
2
Question by yawnm3 · Apr 03, 2015 at 09:23 PM · 2dunity5rigidbody2d

Unable to access rigidbody2d.Velocity?

Hi Unity,

Can I know why I am not able to use rigidbody2d.Velocity or rigidbody2d.AddForce? I am using Unity5. I learn from the Unity2d tutorial about player controller and having this problem in my script.

alt text

alt text

capture.png (10.3 kB)
capture.png (5.2 kB)
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 savlon · Apr 03, 2015 at 11:39 PM 0
Share

If you are running Unity 5 then you will need to obtain your own reference to the attached rigidbody... It is no longer accessible via "rigidbody2D". Use GetComponent ins$$anonymous$$d.

3 Replies

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

Answer by DoTA_KAMIKADzE · Apr 03, 2015 at 09:31 PM

 private Rigidbody2D rigi;
 private void Awake()
 {
     rigi = GetComponent<Rigidbody2D>();
 }
 void Update()
 {
     //blablabla
     rigi.AddForce(new Vector2(0,700f));
     //blablabla
     rigi.velocity = new Vector2(1f, 2f);
     //blablabla
 }
Comment
Add comment · Show 5 · 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 kanisht sahlot · Dec 30, 2015 at 08:23 AM 0
Share

it works thanks

avatar image syifarnd · Apr 15, 2016 at 10:03 AM 0
Share

thank you !

avatar image Evelles · May 24, 2016 at 11:49 PM -1
Share

thank you. I looked every where for the answer to this. This worked perfectly.

avatar image thelonelyisl44nd · Jan 28, 2017 at 09:54 AM -1
Share

it works ! I looked everywhere for the answer to this.

avatar image douglasdaquino · Apr 21, 2017 at 07:16 PM 0
Share

thank you! you rock DoTA_$$anonymous$$A$$anonymous$$I$$anonymous$$ADzE!!

avatar image
6

Answer by jcv8000 · Apr 03, 2015 at 09:29 PM

Use

GetComponent<Rigidbody2D>()
instead of
rigidbody2d
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 Supam · Aug 02, 2017 at 08:49 PM 0
Share

thanks a lot

avatar image
0

Answer by Sves100 · Jul 20, 2018 at 12:18 AM

@DoTA_KAMIKADzE Hey, hope I dont break some necromancing rules but I would appriciate your help. I tried piecing lines of codes together from various tutorials to get it working it still floats after I stop pressing the button which should be the problem here but I cant rely figurate out what to do or what to replace to fix it

 using UnityEngine;
 using System.Collections;
 
 public class PlayerController : MonoBehaviour 
 {
 
     public float speed;             //Floating point variable to store the player's movement speed.
 
     private Rigidbody2D rb2d;       //Store a reference to the Rigidbody2D component required to use 2D Physics.
 
     // Use this for initialization
     void Start()
     {
         //Get and store a reference to the Rigidbody2D component so that we can access it.
         rb2d = GetComponent<Rigidbody2D> ();
     }
 
     //FixedUpdate is called at a fixed interval and is independent of frame rate. Put physics code here.
     void FixedUpdate()
     {
         //Store the current horizontal input in the float moveHorizontal.
         float moveHorizontal = Input.GetAxis ("Horizontal");
 
         //Store the current vertical input in the float moveVertical.
         float moveVertical = Input.GetAxis ("Vertical");
 
         //Use the two store floats to create a new Vector2 variable movement.
         Vector2 movement = new Vector2 (moveHorizontal, moveVertical);
 
         //Call the AddForce function of our Rigidbody2D rb2d supplying movement multiplied by speed to move our player.
         rb2d.AddForce (movement * speed);
     }
 }
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

14 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

Related Questions

the player is flying off the ramp (collider) 1 Answer

,Hey! I'm trying to make a Dash move like Celeste but my Dash doesn't seem to work Horizontally(X Axis), My Dash is working perfectly fine Upward and Downwards(Y Axis). 1 Answer

Prevent gameobjects from overlapping - 2D 0 Answers

How to freeze all enemy objects at once 1 Answer

Deteriorating force on object? 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