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 /
This question was closed Mar 11, 2015 at 03:06 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by digitaltoon · Sep 23, 2013 at 04:40 PM · tutoriallearn

Project #00: Roll-a-Ball Tutorial Error

I am working through the tutorial Project #00: Roll-a-Ball in Learn/Tutorial/Projects. In part two Moving the player I get an error at 09:38 of the video. Can anyone tell me what I am doing wrong here?

 using UnityEngine;
 using System.Collections;
 
 public class PlayerController : MonoBehaviour 
 {
     void FixedUpdate ()
     {
         float moveHorizontal = Input.GetAxis("Horizontal");
         float moveVertical = Input.GetAxis("Vertical");
         
         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
         
         rigidbody.Addforce(movement);
     }
 }

and the error message is

Assets/Scripts/PlayerController.cs(13,27): error CS1061: Type UnityEngine.Rigidbody' does not contain a definition for Addforce' and no extension method Addforce' of type UnityEngine.Rigidbody' could be found (are you missing a using directive or an assembly reference?)

Comment
Add comment · Show 3
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 Brucem55 · Feb 16, 2014 at 02:37 PM 0
Share

I am having the same issue, however my script looks correct when comparing line by line to the project: using UnityEngine; using System.Collections;

public class PlayerController : $$anonymous$$onoBehaviour { void Fixedupdate () { float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical");

         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);

         rigidbody.AddForce(movement);
     }

}

Any ideas?? I notice some referenced there is no attachment for the rigidbody object. How do you reference a rigidbody object without recreating it?

avatar image slippdouglas · Jan 15, 2015 at 04:04 AM 0
Share

-1: This isn't a issue with Unity or the tutorial.  It's just a basic reading/writing mistake made by the OP.  So the question isn't necessarily unwelcome— it just has very low usefulness to anyone other than the OP.

avatar image erikbc · Mar 12, 2015 at 06:27 AM 0
Share

This is not true. If you read my answer, you will see that the OP got confused because of a deprecated property. In his case it looks like he was using $$anonymous$$onoDevelop, and it did not warn him about this. In $$anonymous$$onoDevelop, code completion, simply won't show the property.

$$anonymous$$ore beginners will encounter this same "problem".

5 Replies

  • Sort: 
avatar image
4
Best Answer

Answer by robertbu · Sep 23, 2013 at 06:18 PM

The function is 'AddForce()' with an upper case 'F', not 'Addforce()'. Both C# and Javascript are case sensitive.

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 digitaltoon · Sep 23, 2013 at 06:33 PM 0
Share

Well my mother always said I sucked at typing and that indeed is the case...THAN$$anonymous$$S SO $$anonymous$$UCH...this was my first attempt at learning program$$anonymous$$g in Unity and I had not enough sleep when I attempted it. AddForce it is!

avatar image digitaltoon · Sep 23, 2013 at 06:49 PM 0
Share

I just noticed another thing and this is after adding a Speed property to the script. I can scroll with my cursor over the Speed text(the arrows going both ways show) but I cannot just go into the text box to change it. This appears also to be the case for the rigidbody section ,sphere collider but not the transform area..those I can hi-lite and I see blue.Other ones I mentioned I can't get that to appear.

avatar image Ashok77 · Mar 07, 2015 at 04:00 PM 0
Share

$$anonymous$$e doesn't work even though i write "AddForce"........ help

avatar image
3

Answer by stalky47 · Mar 06, 2015 at 05:07 PM

this works

using UnityEngine; using System.Collections;

 public class PlayerController : MonoBehaviour
 {
     public float speed;
     public Rigidbody rb;

     void fixedupdate ()
     {
         float moveHorizontal = Input.GetAxis ("Horizontal");
         float moveVertical = Input.GetAxis ("Vertical");
         
         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
         
         rb.AddForce(movement * speed * Time.deltaTime);
     }
 }

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 mameaddicts · Mar 11, 2015 at 05:50 AM 1
Share

I see the tutorial is check with 4.0, and I have Unity 5. Is this why my code does not work? It is line by line an exact match with the lesson. I get the same error too. Thanks! There is a space in movement that I cannot prevent from happening and rigidbody always wants to capitalize the "R".

 using UnityEngine;
 using System.Collections;
 
 public class PlayerController : $$anonymous$$onoBehaviour
 {
     void FixedUpdate ()
     {
         float moveHorizontal = Input.GetAxis("Horizontal");
         float moveVertical = Input.GetAxis("Vertical");
 
         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
 
         rigidbody.AddForce (movement);
     }
 }
avatar image meat5000 ♦ · Mar 11, 2015 at 05:54 AM 0
Share

rigidbody always wants to capitalize the "R".

Thank you for this very important piece of information I have been searching for.

You need to use GetComponent to reference the rigidbody as the aliases/shortcuts are no longer supported in Unity 5.

avatar image mameaddicts · Mar 11, 2015 at 03:02 PM 0
Share

Thanks $$anonymous$$eat5000!

The tutorial says tested with 4.0. So could I assume that is I were to use version 4.0, then the tutorials would be correct?

As a beginner, it really helps to have accurate tutorials. What do you seasoned devs recommend?

Should I roll back to 4.0, or should I continue to wing it on 5.0?

avatar image meat5000 ♦ · Mar 11, 2015 at 03:03 PM 0
Share

Check it :)

avatar image erikbc · Mar 12, 2015 at 06:21 AM 0
Share

mameaddicts: The tutorials are fine, there are a few version differences, but they are usually $$anonymous$$or. I would recommend going through all the available tutorials, never$$anonymous$$d which version of Unity they are made with. Game development and program$$anonymous$$g is all about solving problems, you might actually learn more this way, as it forces you to think and find a solution, as opposed to just mechanically doing step by step.

Pay attention to what your IDE is telling you. In this case, Visual Studio told me that this way of doing things were obsolete/deprecated, it even told me how I should do it, and if you are still unsure how, at the very least you know what to search for in the Unity Script Reference.

I don't use $$anonymous$$onoDevelop, it is not as good as Visual Studio, in a number of ways, Visual Studio 2013 Community Edition is free, I recommend that as an IDE for beginners and professionals, also, UnityVS, which is an extension for Visual Studio that helps with debugging.

https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx

http://unityvs.com/

avatar image
1

Answer by erikbc · Mar 11, 2015 at 07:40 AM

Property 'UnityEngine.Component.rigidbody' is obsolete: The property has been deprecated. Use GetComponent<Rigidbody>() instead.

So, what you do instead of what's in the tutorial is something like this:

 public class PlayerController : MonoBehaviour
 {
      public Rigidbody rb;
 
      void Start()
      {
         rb = GetComponent<Rigidbody>();
      }
 
      void FixedUpdate()
      {
         rb.AddForce(movement * moveSpeed * Time.deltaTime);
      }
 }



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
avatar image
0

Answer by Seizure · Sep 23, 2013 at 05:25 PM

The gameobject that this script is attached to does not have a rigidbody, either add one or reference the gameobject that does have the rigidbody.

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 digitaltoon · Sep 23, 2013 at 05:58 PM 0
Share

The gameobject does have a rigidbody attached to it.

avatar image
0

Answer by TrixieandMindy · Feb 23, 2015 at 04:18 PM

i think you need this part of the script

rigidbody.AddForce(movement speed Time.deltaTime);

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

Follow this Question

Answers Answers and Comments

23 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

Related Questions

Raycast tutorials? 1 Answer

Where I could find old Unity 3.5 tutorials? 0 Answers

Book/tutorial for experienced programmers 3 Answers

Custom mouse cursor - looking for a really good tutorial. 1 Answer

Free kick unity3d tutorial 1 Answer


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