# 2D Flight problem

Hello, im in the process of creating a 2D game based on bird-like flight. Basically you can fly up, down, left and right in a 2D platform type game using the WASD keys. Anyway, when flying up and down, the object often drops by itself, twists and bounces around. Is there anyway to fix this issue? I only have a basic understanding of javascript so sorry if i don’t understand.

Code used:

``````#pragma strict

// The 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.
// See http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.FixedUpdate.html
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);
}

// Require a Rigidbody component to be attached to the same GameObject.
@script RequireComponent(Rigidbody)
``````

Thanks
-Caleb

If you don’t want the object to drop by itself, disable gravity. If you don’t want it to rotate due to collisions, freeze the rotation axis/axes that you don’t want to rotate. You can do this in the editor or via script with rigidbody.constraints and rigidbody.useGravity