- Home /
Player/Car fall through plane. Javascript error included
So, I am starting to learn unity. I created a blender file (car) which is now in unity with a charactercontroller and such (LOL, it still includes jumping in the code)
When the car spawns on game start it falls through the ground (yes it is above the plane)
Here is spam i get in the console while it is falling
NullReferenceException: Object reference not set to an instance of an object
Movement.Update () (at Assets/Scripts/Movement.js:10)
Also here is the Movement.js file
#pragma strict
var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
private var moveDirection : Vector3 = Vector3.zero;
function Update() {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) {
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}
Any idea on how to fix this? What is wrong with line 10?
Do items/blends fall through planes? Is the falling causing the error or the script itself. Please help me out.
Your error says that 'controller' is not set to an object, so it looks like 'GetComponent(CharacterController)' failed. Does your car have a rigidbody and a collider? Does the plane have a collider? Is the car exactly on the plane (if so try adding a putting it very slightly above)?
Your answer
![](https://koobas.hobune.stream/wayback/20220613121507im_/https://answers.unity.com/themes/thub/images/avi.jpg)