I found this script on google, because there isn’t many tutorials, im learning from the script itself. The script is from 2010 and represents 2d movement. But it does not work with the new update 4,3 with the 2d features. The script can’t needs a ridgidbody. But now there is a ridgidbody 2D feature, and that is the ridgidbody i use.
It says in the console log, that no ridgidbody is attached to my 2d player but the script is trying to acces the ridgidbody, and i use the 2d ridgidbody.
Ive tried modifying it and saying ridgidbody2d instead and some other stuff but it does not work. Can you help?
// The horizontal speed of the keyboard controls. A higher value will
// cause the object to move more rapidly.
var keyboardSpeed = 20.0;
// FixedUpdate is a built-in unity function that is called every fixed framerate frame.
// According to the docs, FixedUpdate should be used instead of Update when dealing with a
// Rigidbody.
function FixedUpdate () {
// This is where we move the object.
// Get input from the keyboard, with automatic smoothing (GetAxis instead of GetAxisRaw).
// We always want the movement to be framerate independent, so we multiply by Time.deltaTime.
var keyboardX = Input.GetAxis("Horizontal") * keyboardSpeed * Time.deltaTime;
var keyboardY = Input.GetAxis("Vertical") * keyboardSpeed * Time.deltaTime;
// Calculate the new position based on the above input.
// If you want to limit the movement, you can use Mathf.Clamp
// to limit the allowed range of newPos.x or newPos.y.
var newPos = rigidbody.position + Vector3(keyboardX, keyboardY, 0.0);
// Move the object.
rigidbody.MovePosition(newPos);
}