Hello,
I created simple 2d space shooter where my object only move along x and z axis and rotate along Y axis towards mouse cursor(I used LookAtMouse script in C# from wiki).
But right now Im thinking about creating 3d space shooter, where my ship can move in 3d space environment, like in those games:
But I dont know where to start unfortunately… Do you know anything that could help me? Or I need to buy some projects in Asset Store and look at source code?
There are a many free scripts on the web, also free projects to get your hands on. For anyone new to Unity it’s a good idea to just download everything Unity. All tutorials, scripts and other resources. Then go through the tutorials to see how things work. This builds a nice library of scripts to reference from in the future.
Space games don’t have gravity ( most the time lol) so a rigidbody with its gravity turned off and the use of rigidbody add force is one way to go. Then all you need is the smooth camera script that comes with Unity.
You can play whit this script , i use it a lot in most occasions. Hope help you.
#pragma strict
// velocidade do movimento do jogador para cima.
var jogadorCima : int = 5;
// velocidade do movimento do jogador para baixo.
var jogadorBaixo : int = 5;
// velocidade do movimento do jogador para Direita.
var jogadorDireita : int = 5;
// velocidade do movimento do jogador para Esquerda.
var jogadorEsquerda : int = 3;
// velocidade do movimento do jogador para Direita automático pelo nível.
var velocidaFrontal : float = 0.05;
var maximoPontos : int = 100;
static var pontosActual = 0;
static var vidas : int = 3;
// acções tiros
var tiro1a : Rigidbody;
//var activo : int = 1;
var bulletTotal : int = 50;
function Start ()
{
// Check and get the current points saved data.
pontosActual = PlayerPrefs.GetInt("Pontos");
}
function Update ()
{
if (Input.GetKey(KeyCode.W))
{
// Move o jogador para cima.
transform.Translate(0,0,1 * jogadorCima * Time.deltaTime);
}
if (Input.GetKey(KeyCode.S))
{
// Move o jogador para baixo.
transform.Translate(0,0,1 * -jogadorBaixo * Time.deltaTime);
}
if (Input.GetKey(KeyCode.D))
{
// Move o jogador para Direita.
transform.Translate(1 * jogadorDireita * Time.deltaTime,0,0);
transform.Rotate(0,1 * 100 * Time.deltaTime, 0);
}
if (Input.GetKey(KeyCode.A))
{
// Move o jogador para esquerda.
transform.Translate(1 * -jogadorEsquerda * Time.deltaTime,0,0);
transform.Rotate(0,1 * -100 * Time.deltaTime, 0);
}
// controla o arranque da nave e paragem.
//if (activo)
//{
// Move a nave automatico pelo nivel.
//transform.Translate(0,0,1 * velocidaFrontal);
//}
// Controlo das armas.
// Disparo standard
if (Input.GetKeyDown(KeyCode.Space) bulletTotal)
{
var tempTiro1a : Rigidbody;
tempTiro1a = Instantiate(tiro1a, transform.position, transform.rotation);
bulletTotal --;
if (bulletTotal == 0)
{
bulletTotal += 100;
}
}
//****************************
if (Input.GetKey(KeyCode.Alpha1))
{
Debug.Log("Arma 1 activa");
}
if (Input.GetKey(KeyCode.Alpha2))
{
Debug.Log("Arma 2 activa");
}
if (Input.GetKey(KeyCode.Alpha3))
{
Debug.Log("Arma 3 activa");
}
if (Input.GetKey(KeyCode.Alpha4))
{
Debug.Log("Arma 4 activa");
}
// Controlo de pontos
if (pontosActual < 0)
{
pontosActual = 0;
}
if (pontosActual > maximoPontos)
{
pontosActual = maximoPontos;
}
if (pontosActual < 0)
{
pontosActual = 0;
}
// Verifica se está no máximo de pontos
if (pontosActual >= maximoPontos)
{
Debug.Log("Full Points");
}
}
function OnGUI()
{
GUI.Label(Rect(10,10,200,50),"Pontos: " + pontosActual);
GUI.Label(Rect(10,30,200,50),"Vidas: " + vidas);
}
@script ExecuteInEditMode()
Also, even if I will use rigibody, how Can I rotate my ship with camera. Is there any tutorial for that?
I mean that I wanna do something like that my ship will follow my camera and rotate with my mouse?
For example:
I press “W” key so my ship is start moving ahead, then I use my mouse to rotate my ship so he can get to the higher point.
Hey Zoboleq, I’d suggest using the “Space Game Starter Kit” It is really easy if you are willing to look through the code. Completely modular and very simple to add new modules for. It is on the asset store by a group called Tasharen, same mob who made the NGUI. Helped me out a lot.
I saw that once, but it is to expensive for me and I think that I prefer self-learning method through tutorials. Unfortunately there is lack of this kind tutorials…
#pragma strict
// movement speed of the player upwards.
var playerUp : int = 5;
// movement speed of the player down.
var playerdown : int = 5;
// movement speed of the player to the right.
var playerRight : int = 5;
// movement speed of the player to left.
var playerleft : int = 3;
// movement speed of the player to the right automatic level.
var frontalSpeed : float = 0.05;
var maxPoints : int = 100;
static var curPoints = 0;
static var Life : int = 3;
// acções tiros
var tiro1a : Rigidbody;
//var activo : int = 1;
var bulletTotal : int = 50;
function Start ()
{
// Check and get the current points saved data.
curPoints = PlayerPrefs.GetInt("Points");
}
function Update ()
{
if (Input.GetKey(KeyCode.W))
{
// Move the player up.
transform.Translate(0,0,1 * playerUp * Time.deltaTime);
}
if (Input.GetKey(KeyCode.S))
{
// Move the player down.
transform.Translate(0,0,1 * -playerdown * Time.deltaTime);
}
if (Input.GetKey(KeyCode.D))
{
// Move the player to Right.
transform.Translate(1 * playerRight * Time.deltaTime,0,0);
transform.Rotate(0,1 * 100 * Time.deltaTime, 0);
}
if (Input.GetKey(KeyCode.A))
{
// Move the player to left.
transform.Translate(1 * -playerleft * Time.deltaTime,0,0);
transform.Rotate(0,1 * -100 * Time.deltaTime, 0);
}
// controls the starting and stopping of the ship.
//if (activo)
//{
// Move the ship automatically by level.
//transform.Translate(0,0,1 * frontalSpeed);
//}
// Arms Control.
// Shooting standard
if (Input.GetKeyDown(KeyCode.Space) bulletTotal)
{
var tempTiro1a : Rigidbody;
tempTiro1a = Instantiate(tiro1a, transform.position, transform.rotation);
bulletTotal --;
if (bulletTotal == 0)
{
bulletTotal += 100;
}
}
//**************************** F1, F2, F3,F4 ***************************************
if (Input.GetKey(KeyCode.Alpha1))
{
Debug.Log("Weapon 1 active");
}
if (Input.GetKey(KeyCode.Alpha2))
{
Debug.Log("Weapon 2 active");
}
if (Input.GetKey(KeyCode.Alpha3))
{
Debug.Log("Weapon 3 active");
}
if (Input.GetKey(KeyCode.Alpha4))
{
Debug.Log("Weapon 4 active");
}
// Control points
if (curPoints < 0)
{
curPoints = 0;
}
if (curPoints > maxPoints)
{
curPoints = maxPoints;
}
if (curPoints < 0)
{
curPoints = 0;
}
// Checks whether this in maximum points
if (curPoints >= maxPoints)
{
Debug.Log("Full Points");
}
}
function OnGUI()
{
GUI.Label(Rect(10,10,200,50),"Points: " + curPoints);
GUI.Label(Rect(10,30,200,50),"Life: " + Life);
}
@script ExecuteInEditMode()