bonjour, j'aimerais faire une camera orbital pour mon jeux, et j'ai un problème avec mon script:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using UnityEngine;
using System.Collections;
 
public class OrbitCamera : MonoBehaviour
{
	public Transform target;
	public float distance = 20.0f;
	public float zoomStep = 1.0f;
	public float xSpeed = 1f;
	public float ySpeed = 1f;
	private float x = 0.0f;
	private float y = 0.0f;
	private Vector3 distanceVector;
 
	void Start ()
	{
		distanceVector = new Vector3 (0.0f, 0.0f, -distance);
		Vector2 angles = this.transform.localEulerAngles;
		x = angles.x;
		y = angles.y;
		this.Rotate (x, y);
	}
	void LateUpdate ()
	{
		if (target)
		{
			this.RotateControls ();
		}
	}
	void RotateControls ()
	{
		if ( Input.GetButton ("Fire1") )
		{
			x += Input.GetAxis ("Mouse X") * xSpeed;
			y += -Input.GetAxis ("Mouse Y")* ySpeed;
			this.Rotate (x, y);
		}
 
	}
	void Rotate (float x, float y)
	{
		Quaternion rotation = Quaternion.Euler (y, x, 0.0f);
		Vector3 position = rotation * distanceVector + target.position;
		transform.rotation = rotation;
		transform.position = position;
	}
}
la camera ne suis pas l'objet en mouvement et la rotation se réinitialise a chaque fois que je fait un clique pour refaire une rotation.