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 $$anonymous$$ · Sep 21, 2016 at 06:59 PM · movementcontroller

Rollerball Tutorial: rb.AddForce(movement * speed); not working?

Well I tried to research this issue to see how common it is and I've found a lot of errors mentioned that I don't seem to have. That being said, I can't find any errors elsewhere and I'm wondering if a second pair of eyes might help?

I am using C#, and the problem seems to come from line 24 based on the error I receive. I tried a couple different things as well, such as changing the command to rb.velocity, but it would not work because it can apparently not be used as a method.

Error:

NullReferenceException: Object reference not set to an instance of an object PlayerControls.FixedUpdate () (at Assets/Scripts/PlayerControls.cs:24)

Code: using UnityEngine; using System.Collections;

 public class PlayerControls : MonoBehaviour
 {
     //Public or Private Declarations
     public float speed = 100.0f;
     private Rigidbody rb;
 
     //initialization of movement
     void start()
     {
         rb = GetComponent<Rigidbody>();
     }
 
     //application to each frame of movement
     void FixedUpdate()
     {
         float moveHorizontal = Input.GetAxis("Horizontal"); //x variable
         float moveVertical = Input.GetAxis("Vertical"); //z variable
 
         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
         
         rb.AddForce(movement * speed);
     }//end FixedUpdate
 }//end Startusing UnityEngine;
 



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 $$anonymous$$ · Sep 20, 2016 at 09:13 PM 0
Share

With the first few lines being removed, it is line 21 in this post. $$anonymous$$y apologies.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Lrr2s · Sep 21, 2016 at 09:16 PM

This might seem patronizing, but did you change the move speed in the inspector? it starts at 0 by default and it took me forever to figure out what was going on when i did it.

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 $$anonymous$$ · Sep 23, 2016 at 06:47 AM 0
Share

Not patronizing at all. I did start using the speed control through unity. It worked initially. Then it stopped working once I started playing with camera as a child and such. After that I tried setting it in the code.

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

79 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 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 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

Adding proper air control to RigidbodyFirstPersonController 1 Answer

How do I get a character to walk on walls and ceilings? 1 Answer

Trouble carrying over scripted gravity to NPC. 0 Answers

Control Air movement with character controller 0 Answers

Why can my character controlled player can stand on the side of a block? 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