Controls Help

Hi. I am fairly new to unity and am trying to learn JavaScript and C#…however, I’m not quite there…so, I need some help.

I have a rigidbody object (a spaceship) which is hovering above a plane and has a camera smoothfollowing it. I need to create a basic control system to move the spaceship. I need a script to move it along just the x and z axis using the forward/backward arrows for the z axis and the left/right arrows for the x axis.

All help will be greatly appreciated!

var thrust : float = 10.0;

function Update() {
     constantForce.relativeForce = Vector3(thrust * Input.GetAxis("Horizontal"), 0,thrust * Input.GetAxis("Vertical"));
}

@script RequireComponent(ConstantForce, Rigidbody)

you might want to Freeze Rotation on the rigidbody.

Hope that helps you get started.

That’s perfect! Thanks a lot!

Now, can anyone tell me how to make the ship rotate a little bit to the left or a little to the right, depending on the input from the arrow keys, and how would I get the camera to tilt with it? Also, how would I call up an animation to play on the ship then it “rolls” on the rotation?

For example, if the user presses left, the ship turns slightly to the left and the camera follows, but that would look awkward. I have an animation to make the craft “dip” to the left a little bit to make it look more realistic, I’m just wondering how I would key that to happen when the key is pressed. (much like on the iphone video on the home page)