cancel
Showing results for 
Search instead for 
Did you mean: 

3rd person space shooter

mike9189
Honored Guest
I am making a third person space shooter.  I want to fly in the direction I am looking, i have the camera attached to the ship, but the problem i have is that when I turn the ship goes out of view. For example if I turn 90 degrees to the left my camera and ship will face left but the ship's position is still in front of the camera in the z direction instead of the x. One thing I thought might work would be to rotate the ship around the camera or the camera around the ship when I turn, or to disable head tracking because it works fine in unity using the mouse to steer but I don't know how.  I don't know if this makes sense, but I don't know how to explain it. If anyone has a solution I would appreciate it. Also I am new to VR and unity so if you could explain it in detail it would help a lot thanks. 
This is the code I am using to turn the ship.
public class AlignToTracker : MonoBehaviour {
public Transform hmdOrientation; //in the inspector add the "OVRCameraRig/CenterEyeAnchor"

private float adjustPos=1;

private Vector3 tempRot;
// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {


tempRot.x = hmdOrientation.localEulerAngles.x;
tempRot.y = hmdOrientation.localEulerAngles.y;
tempRot.z = hmdOrientation.localEulerAngles.z;

//update head rotation
transform.localEulerAngles = tempRot;
}
}


1 REPLY 1

Fulby
Heroic Explorer
You could have the ship attached (i.e. be a child of) of the camera, so it will always appear in front of the camera. This is the opposite of what you have now I think (your description sounds like the camera is a child of the ship).

This probably won't provide good gameplay though as there will be no independent acceleration/turning of the ship. To get that I would make the ship and camera on separate game objects, have a 'target location' which is a child of the camera, and have a script that moves the ship towards the target with limited speed/acceleration. This way it will lag behind when the player moves their head quickly.