- Home /
When I am coding in C# for my player to move in space shooter rigidbody.velocity = movement; refuses to be recognized. Why? and what can i do to fix this?
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.velocity = movement;
}
}
The last line of code rigidbody.velocity = movement; is not recognized by unity. I followed every single step that the tutorial told me to do and I have checked the done examples and my friends have looked it over and so has my teacher. No one understands why it won't work. I have re-created my Unity space shooter game for the second time. I do not understand what I have done wrong. PLEASE HELP!!!!
Here is the tutorial i was following to move my player. I have everything he does except my game won't run and it does not register my "rigidbody.velocity".... Space Shooter - Unity - Moving the Player
Do your game object have a rigidbody?, what do you meant with "not recognized", what is the error that you receive at the console window?
Answer by Baste · May 21, 2015 at 02:41 PM
Are you using Unity 5?
Unity 5 deprecated the .rigidbody variable, as it wasn't obvious that it did a .GetComponent behind the scenes.
Replace this:
rigidbody.velocity = movement;
with:
GetComponent<rigidbody>().velocity = movement;
Unity should have asked you to update that automatically for you, and the error message should have mentioned that "UnityEngine.Component.rigidbody' is obsolete: `Property rigidbody has been deprecated. Use GetComponent() instead."