Ship Controls

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.

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 ^^

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).

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.

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!

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

Oh duh, I didn’t see that.
Thanks.

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

function FixedUpdate () {
If(Input.GetButton ("HeadlightToggle"))

Toggle Headlights (check/uncheck already placed lights)


}

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.

You’ll probably want a script more like this:

private var headlightsOn  = false;

function Update () {
     if(Input.GetKey("q")) {         // "q" could be any key you want it to be - arbitrary
          // I suggest saying something like...
          headlightsOn = !headlightsOn;     //this switches whether lights are on or not
          // and then... 
          flipHeadlights(headlightsOn);
     }
}

//you would then need a coroutine down here...
function flipHeadlights ( isOn ) {
     if( isOn ) {
           //turn on two spotlights that you put on your car
     } else if ( !isOn ) {
           //turn off two spotlights that you put on your car
     }
}

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.

Seeing as I’m lost when i comes to scripting, I can use all that help I can get. Thanks.

One more newb question… :sweat_smile:
What do I need to add to the headlight script to make it functional?

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.

var headlightLeft : Light;
var headlightRight: Light;
private var headlightsOn  = false;

function Update () { 
	if(Input.GetKeyDown("q")) {         // "q" could be any key you want it to be - arbitrary 
		// I suggest saying something like... 
		headlightsOn = !headlightsOn;     //this switches whether lights are on or not 
		// and then... 
		flipHeadlights(headlightsOn); 
	} 
} 

//you would then need a coroutine down here... 
function flipHeadlights ( isOn ) { 
	if( isOn ) { 
		//turn on two spotlights that you put on your car
		headlightLeft.color = Color.white;
		headlightRight.color = Color.white;
	} else if ( !isOn ) { 
		//turn off two spotlights that you put on your car 
		headlightLeft.color = Color.black;
		headlightLeft.color = Color.black;
	} 
}

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!

Thank’s a lot! That’s great.
I think I might actually be learning javascript.

That’s the spirit!