Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Constant Force With x,y,z Movement

Discussion in 'Scripting' started by Brkr133, Jun 20, 2014.

  1. Brkr133

    Brkr133

    Joined:
    May 21, 2014
    Posts:
    2
    Hello Dear Friends,


    First of all , i want to create a space flight game and in this game my ship should move constantly to the one direction. Moreover, while my ship goes to its way i have to control my ship in 3d dimension with my mouse. I tried several things im not a professional coder so i need some help with this kind of script. I found constantForce script and some Mouse Controller Script from the forum but i couldnt combine them together. ( Ship has to be Rigidbody)

    I found this for Mouse Controller :

    var force : Vector3;
    var relativeTorque : Vector3;


    function Start() {
    Screen.lockCursor = true;
    }

    function FixedUpdate() {
    // Turn
    var h = Input.GetAxis("Mouse X");
    var v = Input.GetAxis("Mouse Y");

    rigidbody.AddRelativeTorque(0, h * 20, v * 20);

    }


    And this one is for ConstantForce :

    var force : Vector3;
    var relativeTorque : Vector3;
    var liftSpeed : float;
    var turnSpeed: float;

    function Start () {

    }

    function Update () {
    if (Input.GetButtonDown("Fire1")) {

    constantForce.force= Vector3.forward * liftSpeed;


    As i said if i only use constant force it is okay when i click to game ship goes its way but i cannot control it . On the other hand when i try to embed this code to mouse control script nothing happens. If possible i need some help.
    Thanks,
     
  2. Cinema

    Cinema

    Joined:
    Sep 19, 2013
    Posts:
    18
  3. Brkr133

    Brkr133

    Joined:
    May 21, 2014
    Posts:
    2
    So can i implement the mouse axis codes into this one ? i really need help with this combination