1. 设定一个位置,可以在其前方放置一个显示其位置的cube。这里也可以写脚本设定位置。 2. 使用函数 移动函数 transform.position = vector3.slerp(positionstart, positionEnd, Time*time*0.001); 旋转函数 transform.Rotation = Quaternion.slerp(StartRotation, aimRotation, Time.time*0.00001); 3.在控制自动漫游于原始FPC摄像机的切换脚本中添加功能:按下run,自动记录当前position,rotation;按Fps,恢复原来位置; 4. aimRotation制定: 4.1 由于我的摄像机一开始旋转了180度,因此需要添加 aimRotation = Inverse(CubeRotation); aimRotation.y = 180度 + aimRotation.y; 4.2 当移动到aimpostion时,FPS在轻微移动,因此加上判断;FPS与aimPostion 很近的时候,就直接将位置赋值给FPS; Time Time.time 这一帧执行的时间距离开始时间 Time.deltatime * 10 每帧移动10米 这段脚本是我写的包含控制函数使得摄像机首先扭转方向到目标物体,然后按照该方向飞向目标物体,包含当物体里目标位置很近的时候,模糊摄像机,然后恢复正常状态 [size=1em][size=1em]1
[size=1em]2
[size=1em]3
[size=1em]4
[size=1em]5
[size=1em]6
[size=1em]7
[size=1em]8
[size=1em]9
[size=1em]10
[size=1em]11
[size=1em]12
[size=1em]13
[size=1em]14
[size=1em]15
[size=1em]16
[size=1em]17
[size=1em]18
[size=1em]19
[size=1em]20
[size=1em]21
[size=1em]22
[size=1em]23
[size=1em]24
[size=1em]25
[size=1em]26
[size=1em]27
[size=1em]28
[size=1em]29
[size=1em]30
[size=1em]31
[size=1em]32
[size=1em]33
[size=1em]34
[size=1em]35
[size=1em]36
[size=1em]37
[size=1em]38
[size=1em]39
[size=1em]40
[size=1em]41
[size=1em]42
[size=1em]43
[size=1em]44
[size=1em]45
[size=1em]46
[size=1em]47
[size=1em]48
[size=1em]49
[size=1em]50
[size=1em]51
[size=1em]52
[size=1em]53
[size=1em]54
[size=1em]55
[size=1em]56
[size=1em]57
[size=1em]58
[size=1em]59
[size=1em]60
[size=1em]61
[size=1em]62
[size=1em]63
[size=1em]64
[size=1em]65
[size=1em]66
[size=1em]67
[size=1em]68
[size=1em]69
[size=1em]70
[size=1em]71
[size=1em]72
[size=1em]73
[size=1em]74
[size=1em]75
[size=1em]76
[size=1em]77
[size=1em]78
[size=1em]79
[size=1em]80
[size=1em]81
[size=1em]82
[size=1em]83
[size=1em]84
[size=1em]85
[size=1em]86
[size=1em]87
[size=1em]88
[size=1em]89
[size=1em]90
[size=1em]91
[size=1em]92
[size=1em]93
[size=1em]94
[size=1em]95
[size=1em]96
| [size=1em][size=1em]var startObject : GameObject;
[size=1em]var aimObject : GameObject;
[size=1em]var aimObjectLocation : GameObject;
[size=1em]var maincamera : Camera;
[size=1em]private var PositionStart : Vector3;
[size=1em]private var PositionEnd : Vector3;
[size=1em]private var aimRotation : Quaternion;
[size=1em]private var startRotation : Quaternion;
[size=1em]private var distance : float = 10;
[size=1em]private var angle : float = 10;
[size=1em]private var isBlur : boolean = false;
[size=1em]private var isCloseEnough : boolean = false;
[size=1em]private var relativePos : Vector3;
[size=1em]private var rotationFinished : boolean = false;
[size=1em]private var angleDefinition : boolean = false;
[size=1em]private var translateBegin : boolean = false;
[size=1em]function Update () {
[size=1em] PositionStart = startObject.transform.position;
[size=1em] PositionEnd = aimObjectLocation.transform.position;
[size=1em] if(!translateBegin)
[size=1em] {
[size=1em] relativePos = aimObject.transform.position - PositionStart;
[size=1em] if(transform.position == PositionEnd)
[size=1em] {
[size=1em] rotationFinished = true;
[size=1em] }
[size=1em] else
[size=1em] {
[size=1em] if(relativePos != Vector3.zero)
[size=1em] {
[size=1em] aimRotation = Quaternion.LookRotation(relativePos);
[size=1em] }
[size=1em] else
[size=1em] {
[size=1em] rotationFinished = true;
[size=1em] }
[size=1em] var angle = Quaternion.Angle(transform.rotation, aimRotation);
[size=1em] if (angle != 0)
[size=1em] {
[size=1em] rotationFinished = false;
[size=1em] //distance = 10;
[size=1em] }
[size=1em] else
[size=1em] {
[size=1em] rotationFinished = true;
[size=1em] }
[size=1em] }
[size=1em] }
[size=1em] if(!rotationFinished)
[size=1em] {
[size=1em] if(angle > 0.1)
[size=1em] {
[size=1em] print("rotationlast");
[size=1em] transform.rotation = Quaternion.Slerp(startObject.transform.rotation,
[size=1em] aimRotation, 0.15);//normal velocity
[size=1em] }
[size=1em] else
[size=1em] {
[size=1em] print("rotationTheSame");
[size=1em] rotationFinished = true;
[size=1em] transform.rotation = aimRotation;
[size=1em] translateBegin = true;
[size=1em] }
[size=1em] }
[size=1em]
[size=1em] if(translateBegin)
[size=1em] {
[size=1em] distance = Vector3.Distance(transform.position, PositionEnd);
[size=1em] print(distance);
[size=1em] if(distance < 0.1)
[size=1em] {
[size=1em] print("distance< 0.1");
[size=1em] transform.position = PositionEnd;
[size=1em] translateBegin = false;
[size=1em]
[size=1em] WaitToBlur();
[size=1em] //maincamera.orthographic = true;
[size=1em] transform.rotation = aimObjectLocation.transform.rotation;
[size=1em] }
[size=1em] else
[size=1em] {
[size=1em] transform.LookAt(aimObject.transform);
[size=1em] transform.position = Vector3.Slerp(PositionStart,PositionEnd,
[size=1em] 0.08);
[size=1em] }
[size=1em] }
[size=1em]}
[size=1em]function WaitToBlur() {
[size=1em] // suspend execution for waitTime seconds
[size=1em] var blurCamera= maincamera.GetComponent("BlurEffect");
[size=1em] blurCamera.enabled = true;
[size=1em] yield WaitForSeconds (0.5);
[size=1em] blurCamera.enabled = false;
[size=1em]}
|
|