Object reference not set to an instance of an object
This statement holds the clue: playerRigidBody.MovePosition(transform.position + movement);
I am still trying to figure this out. removed all mesh and other placed objects.
using UnityEngine;
using System.Collections;
public class CharacterMovement : MonoBehaviour
{
public float speed = 6f;
public float turnSpeed = 60f;
public float turnSmoothing = 15f;
private Vector3 movement; //x,y,z movement
private Vector3 turning; //x,y,z, turning
private Animator anim; //Animator variable
private Rigidbody playerRigidBody; //Game objects act under control of physics
void awake()
{
//Get references
playerRigidBody = GetComponent<Rigidbody>();
anim = GetComponent<Animator>();
}
void FixedUpdate()
{
//Store Input Axis
float lh = Input.GetAxisRaw ("Horizontal");
float lv = Input.GetAxisRaw ("Vertical");
Move (lh, lv);
Animating (lh, lv);
}
void Move (float lh, float lv)
{
//Move the Player
movement.Set (lh, 0f, lv);
movement = movement.normalized * speed * Time.deltaTime;
playerRigidBody.MovePosition(transform.position + movement);
if (lh != 0f || lv != 0f)
{
Rotating (lh, lv);
}
}
void Rotating(float lh, float lv)
{
Vector3 targetDirection = new Vector3 (lh, 0f, lv);
Quaternion targetRotation = Quaternion.LookRotation (targetDirection, Vector3.up);
Quaternion newRotation = Quaternion.Lerp (GetComponent <Rigidbody>().rotation, targetRotation, turnSmoothing * Time.deltaTime);
GetComponent<Rigidbody>(). MoveRotation(newRotation);
}
void Animating (float lh, float lv)
{
bool running = lh != 0f || lv != 0f;
anim.SetBool ("IsRunning", running);
}
}