Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Ship Controls

Discussion in 'Editor & General Support' started by Mindless_Soul, Apr 5, 2006.

  1. Mindless_Soul

    Mindless_Soul

    Joined:
    Feb 1, 2006
    Posts:
    128
    I was intrested in putting together a little top view CTF game. I was looking around for something to get me started when I found the Ship Controls script over at Unify:

    http://unify.bluegillweb.com/scriptwiki/index.php/ShipControls

    It's perfect for what I want.

    (see error below)

    My problem is I don't know much of anything about javascript, so I can't figure out why it isn't working. I think I need to change the player controls in the input settings, but it doesn't seem to work.


    Thanks.
     

    Attached Files:

  2. aigam

    aigam

    Joined:
    Dec 31, 2005
    Posts:
    170
    http://www.otee.dk/Documentation/Manual/Input.html

    I have no probed (I'm in a pc now), but it seems that you must add a new input axe with the name "Thrust" and "Turn".

    In the script tutorial this is more explained (it's a good starting tutorial!!).

    If nobody responds, tomorrow I will watch it, but for a start this must serve ^^
     
  3. Mindless_Soul

    Mindless_Soul

    Joined:
    Feb 1, 2006
    Posts:
    128
    Thanks for the link.
    I tried to change the axisNames to "Horizontal" and "Vertical", but that didn't work. I guess I will just add in more inputs.

    What is very strange is that I tried a couple of things, they didn't work, so I put things back to the way they were. I ran my scene, and the script worked fine without any errors. I could move my ship like I wanted. Then as soon as I exited the test, it stopped working. The error returned, and I was back to where I had started.

    Off to change inputs (and go to bed).
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Maybe you didn't save the script the first time around.

    It's going to be easier to just modify the script to use Horizontal and Vertical axis.
     
  5. Mindless_Soul

    Mindless_Soul

    Joined:
    Feb 1, 2006
    Posts:
    128
    I must have forgotten to save. Well whatever, I just made other inputs.
    But now I have a problem that I have run into a couple of times before. When I "thrust" forward, I don't thrust the same way my ship is facing. I have tried a couple of things but it doesn't seem to do anything. If set all rotation to 0, it still doesn't drive straight.

    That script is awesome! It banks, hovers, and everything!
     
  6. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    Play with the forwardDirection variable. It is used to say what is "forward" on a ship. Just make sure you put in a unit vector. (You'll probably keep it all 1F or -1F anyways)

    -Jon
     
  7. Mindless_Soul

    Mindless_Soul

    Joined:
    Feb 1, 2006
    Posts:
    128
    Oh duh, I didn't see that.
    Thanks.

    I was toying around with how I could toggle on and off headlights.

    Code (csharp):
    1. function FixedUpdate () {
    2. If(Input.GetButton ("HeadlightToggle"))
    3.  
    4. Toggle Headlights (check/uncheck already placed lights)
    5.  
    6.  
    7. }
    I need to do something like that, but I don't know the syntax.

    I need to do kind of the same thing for my ship to "shoot".

    Any help would be appreciated.
     
  8. elias723

    elias723

    Joined:
    Feb 10, 2006
    Posts:
    178
    You'll probably want a script more like this:

    Code (csharp):
    1.  
    2.  
    3. private var headlightsOn  = false;
    4.  
    5. function Update () {
    6.      if(Input.GetKey("q")) {         // "q" could be any key you want it to be - arbitrary
    7.           // I suggest saying something like...
    8.           headlightsOn = !headlightsOn;     //this switches whether lights are on or not
    9.           // and then...
    10.           flipHeadlights(headlightsOn);
    11.      }
    12. }
    13.  
    14. //you would then need a coroutine down here...
    15. function flipHeadlights ( isOn ) {
    16.      if( isOn ) {
    17.            //turn on two spotlights that you put on your car
    18.      } else if ( !isOn ) {
    19.            //turn off two spotlights that you put on your car
    20.      }
    21. }
    22.  
    23.  
    For shooting, you'll probably want to do something a lot different than turning on the lights. You probably want to have your car shoot from the front to where the middle of your screen is. I have a script that does this, but you will need to adapt it from a FPS standpoint to whatever you are doing.

    If you want this, I can give it to you also.
     
  9. Mindless_Soul

    Mindless_Soul

    Joined:
    Feb 1, 2006
    Posts:
    128
    Seeing as I'm lost when i comes to scripting, I can use all that help I can get. Thanks.

    One more newb question... :oops:
    What do I need to add to the headlight script to make it functional?
     
  10. elias723

    elias723

    Joined:
    Feb 10, 2006
    Posts:
    178
    Your car would need two headlights as children of it in the hierarchy, and they can be placed wherever on the car you need them. Just rotate them to the direction you want and they should be fine.

    Then, add this script to the car, and in the inspector for the car, there will be a script listed that says "Headlight Left" and "Headlight Right". Find your headlights by clicking on the arrow on the right of those rows, and put them as headlight left and right. Here is the script.

    Code (csharp):
    1.  
    2.  
    3. var headlightLeft : Light;
    4. var headlightRight: Light;
    5. private var headlightsOn  = false;
    6.  
    7. function Update () {
    8.     if(Input.GetKeyDown("q")) {         // "q" could be any key you want it to be - arbitrary
    9.         // I suggest saying something like...
    10.         headlightsOn = !headlightsOn;     //this switches whether lights are on or not
    11.         // and then...
    12.         flipHeadlights(headlightsOn);
    13.     }
    14. }
    15.  
    16. //you would then need a coroutine down here...
    17. function flipHeadlights ( isOn ) {
    18.     if( isOn ) {
    19.         //turn on two spotlights that you put on your car
    20.         headlightLeft.color = Color.white;
    21.         headlightRight.color = Color.white;
    22.     } else if ( !isOn ) {
    23.         //turn off two spotlights that you put on your car
    24.         headlightLeft.color = Color.black;
    25.         headlightLeft.color = Color.black;
    26.     }
    27. }
    28.  
    You can also add more headlights to the script if you want them by adding their names in the same context as the other headlights that I have written in. That way, you could have any number of lights (within reason, of course).

    Good luck!
     
  11. Mindless_Soul

    Mindless_Soul

    Joined:
    Feb 1, 2006
    Posts:
    128
    Thank's a lot! That's great.
    I think I might actually be learning javascript.
     
  12. elias723

    elias723

    Joined:
    Feb 10, 2006
    Posts:
    178
    That's the spirit!