Player flying script

I have made a script in witch you can move, but it uses the ridgid ody component so i can only move while grounded. I would like to add a flying mechanic to my game so that you can move around freely without gravity. What changes would i have to make to my current movment script ? Here’s my current script:
`
function Update () {

 horizontalMovment = Vector2(rigidbody.velocity.x, rigidbody.velocity.z); 
 
 if (horizontalMovment.magnitude > maxRunSpeed){

 horizontalMovment = horizontalMovment.normalized; 
 horizontalMovment *= maxRunSpeed; 
 }
 

 //transform.Rotate(0,cameraObject.GetComponent(PlayerLookScript).currentYRotation, 0, Space.Self);

 rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * runAcceleration, 0, Input.GetAxis("Vertical")* runAcceleration);
 
 transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent(PlayerLookScript).currentYRotation, 0);
 }
`

you could use

transform.Translate(Vector3.forward * Time.deltaTime * maxRunSpeed)

which would move forward in the direction the object is facing at a speed of maxRunSpeed (use anything you like for the speed) this is directly affecting the position of the object, rather than the physics engine processing the movement.

you could change Vector3.forward to whatever you want, for example if you would like to obtain the direction from something other than the object is attached to, then use otherObject.Vector3.forward, and set otherObject to the other object :slight_smile: