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