Hello guys
I’m trying to make a small ship game, where the ship floats a bit above the ground, and of course you can move it forward/backward using the arrow keys, and also turn left/right. Think of the ships in WipeOut.
Since I’m new with Unity and I want to test stuff first, what I did was create a cube, set it as a rigidbody, then added a box for collision. All is fine and the object collides with the track mesh.
My question is, how do I apply movement to the ship?
In my code so far I have something like this:
function FixedUpdate () { forward = Input.GetAxis("Vertical"); //Debug.Log ("Moving forward"+forward+" with deltatime="+Time.deltaTime); if (forward) rigidbody.AddForce(Vector3.forward * 5000 * forward * Time.deltaTime); }
This seems to push the ship forward, although irregularly (it’s more like it’s going over a rocky terrain rather then a plain terrain) and of course it does not use the “ship’s”(cube’s) forward vector (Z axis). Once it collides and the cube rotates, pressing Arrow up does not move the cube forward but sideways. Do I or how do I specify that it should use the ship’s Z axis always, and to make the movement constant over a period of time (say 10 meters/second). Do I use Time.deltaTime or something else since I use FixedUpdate and not Update?