Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

Null Reference Exception..Don't know the answer...

$
0
0
Hi, I just installed unity today on my laptop and started with the roll-a-ball tutorial. Everything seemed to work fine until I reached "Moving the player" section on the list. Here is a link to it : [Roll-a-Ball tutorial by unity][1] The problem is even though I have been following this tutorial very very carefully and closely, I get a Null Reference Exception error whenever I try to add a Force to the rigid body(jump to 12:50 in the video for this). When I play the scene, The console immediately gives me the Null Exception error at line 15( Which in my case is the rb.AddForce(movement); ). However, when I comment that line out, I get no errors but, obviously, that is useless as I am not able to move the player on screen. I have matched the code with the one in the tutorial. Here is the code from my unity environment for your reference : using UnityEngine; using System.Collections; public class PlayerController : MonoBehaviour { private Rigidbody rb; void start() { rb = GetComponent(); } void FixedUpdate() { float moveHorizontal = Input.GetAxis ("Horizontal"); float moveVertical = Input.GetAxis ("Vertical"); Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical); rb.AddForce(movement); } } [1]: https://unity3d.com/learn/tutorials/projects/roll-a-ball/moving-the-player?playlist=17141 Any help is appreciated!!

Viewing all articles
Browse latest Browse all 1264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>