My player moves with the following code.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class PlayerMovement : MonoBehaviour {
public static float maxSpeed = 11f;
public static float rotSpeed = 130f;
public int playernumber;
float shipBoundaryRadius = 0.5f;
private float minput;
void Start () {
minput = Input.GetAxis ("Horizontal" + playernumber);
}
void Update () {
minput = 1;
//Vector3 tragetDirection=new Vector3(minput,0,)
// ROTATE the ship.
// Grab our rotation quaternion
Quaternion rot = transform.rotation;
// Grab the Z euler angle
float z = rot.eulerAngles.z;
// Change the Z angle based on input
z -= Input.GetAxis("Horizontal"+playernumber) * rotSpeed * Time.deltaTime;
// Recreate the quaternion
rot = Quaternion.Euler( 0, 0, z );
// Feed the quaternion into our rotation
transform.rotation = rot;
//MOVE the ship
Vector3 pos = transform.position;
Vector3 velocity = new Vector3(0, minput * maxSpeed * Time.deltaTime, 0);
pos += rot * velocity;
transform.position = pos;
How do I make it move relative to the camera?