E
E
evseev533192016-08-26 19:42:10
Unity
evseev53319, 2016-08-26 19:42:10

How to fix the control and camera script?

Good day to all. The question is actually this: there is a "player" in the form of a sphere, it moves with the help of a script:

public class Move : MonoBehaviour {

Rigidbody rb;
public float speed;
void Start () {

rb = GetComponent<Rigidbody> ();
}


void Update () {

float h = Input.GetAxis ("Horizontal");
float v = Input.GetAxis ("Vertical");
Vector3 move = new Vector3 (h*speed, 0, v*speed);
rb.AddForce (move);

}
}

and there is a camera that moves behind the object using the script:
public class CameraForward : MonoBehaviour {

public GameObject player;
Vector3 offset;
void Start () {
offset =transform.position - player.transform.position;
}


void Update () {
transform.position = player.transform.position + offset;

}
}

The question is: how to make it so that when reaching a certain point, the player and the camera turn 90 degrees, but at the same time the control remains the same relative to the new position. Example: the ball rolls forward (press W) along the road until it turns right, at the place of the turn, the player and the camera turn 90 degrees, and again when the w key is pressed, it moves forward. Sorry for such a primitive explanation. I looked through a lot of information, but did not understand how to do it. I'm new and I need help. Thank you.
ef8a3190e6f74baf9acb27c732e28e51.jpg

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question