My first goal in this project was to get the movement working over anything else. So after getting a dummy ship Malakai made I started to work getting it to move.
I attached three circles as child objects to the ship to act as reticles, as I need a clear view of where the ship is pointing and it helps give a sense of distance.
Movement code (ShipMovement):
using UnityEngine;
using System.Collections;
public class ShipMovement : MonoBehaviour
{
public float movementSpeed = 20.0f;
public int yAxisMovSpeed = 1;
void Update ()
{
float horizontal = Input.GetAxis ("Horizontal");
float vertical = Input.GetAxis("Vertical");
Vector3 direction = new Vector3(horizontal,yAxisMovSpeed*vertical,0);
Vector3 finalDirection = new Vector3(horizontal,yAxisMovSpeed*vertical,1.0f);
transform.position += direction*movementSpeed*Time.deltaTime;
transform.rotation = Quaternion.RotateTowards (transform.rotation, Quaternion.LookRotation (finalDirection), Mathf.Deg2Rad * 50.0f);
}
}
I may need to rethink the movement algorithm as there is a finite distance the player can travel before reaching the end of the plane.
I also would like to layer the plane with transparency to create the illusion of parallax.
I was also able to create movement by instantiating a prefab and applying a force to it.
Forward shoot script (ShootForward):
using UnityEngine;
using System.Collections;
public class ShootForward : MonoBehaviour
{
public Rigidbody bullet;
public float velocity = 10.0f;
// Update is called once per frame
void Update ()
{
if(Input.GetButtonDown("Fire1"))
{
Rigidbody newBullet = Instantiate(bullet,transform.position,transform.rotation) as Rigidbody;
newBullet.AddForce(transform.forward*velocity,ForceMode.VelocityChange);
}
}
}
