原地址:http://www.cnblogs.com/88999660/p/3262656.html

using UnityEngine;
using System.Collections; public class PlayerScript : MonoBehaviour { public GameObject cameraObject;
public float cameraDistance;//the distance the camera should be palced from the palyer
public float cameraHeight;//how heigh the camera should be
private float cameraAngleToPlayer;// the current angle the camera is to the palyer
private Vector3 tempVector; // the temporary vector we shall use for calcuations
// Use this for initialization
void Start () { } // Update is called once per frame
void Update () {
tempVector = Vector3.left;
if(Input.GetKey ("left")) //rotation the angle based on input
{
cameraAngleToPlayer = cameraAngleToPlayer - (Time.deltaTime * 50f);
}else if(Input.GetKey("right")){
cameraAngleToPlayer = cameraAngleToPlayer +(Time.deltaTime *50f);
}
Debug.Log("Quaternion:"+Quaternion.AngleAxis(90f,Vector3.up)+";tempVector:"+tempVector); tempVector = Quaternion.AngleAxis(cameraAngleToPlayer,Vector3.up)*tempVector;//We are now rotating the Vector around the vertical(y) axis by an angle specificed in the variable 'cameraAngleToPlayer'
Debug.Log("tempVector after calculate:"+tempVector);
Debug.DrawLine(transform.position,tempVector*10f,Color.yellow);
cameraObject.transform.position = transform.position + (tempVector.normalized * cameraDistance) + new Vector3(,cameraHeight,);
cameraObject.transform.rotation = Quaternion.LookRotation(transform.position - cameraObject.transform.position);
}
}
以上是绕cube旋转摄像机的示例代码,这段代码拖到cube上。
Quaternion*Vector3的几何意义

例如

Quaternion.AngleAxis(90f,Vector3.up)*Vector3.left

Quaternion:(0.0, 0.7, 0.0, 0.7);Vector3.left:(-1.0, 0.0, 0.0)

calculated:(0.0, 0.0, 1.0)

这样我们得到了从(-1.0, 0.0, 0.0)绕y轴旋转90°的新坐标。

最新文章

  1. python 培训之HTTP
  2. 记OC迁移至swift中笔记20tips
  3. Unity手机平台播放影片
  4. How to Copy and Paste in the Ubuntu Gnome Terminal
  5. C#Winform窗口特效源码(1)
  6. MenuButton( 菜单按钮)
  7. cocos2d-x 3.0 使用最新物理引擎的一个源代码实例
  8. ffplay播放器移植VC的工程:ffplay for MFC
  9. ant+eclipse知识点详解及使用案例
  10. JavaScript夯实基础系列(五):类
  11. Saltstack_使用指南04_数据系统-Grains
  12. oracle--数据筛选
  13. JavaEESSM框架配置文件
  14. [物理学与PDEs]第4章习题2 反应力学方程组形式的化约 - 能量守恒方程
  15. 关于极限精简版系统(RAMOS专用)的说明(FAQ)
  16. mongodb数据导入导出
  17. JAVA传入一个字符串,返回一个字符串中的大写字母
  18. openvpn之安装篇
  19. DWG/DGN格式导入Arcgis;转化为shp格式;更改地理坐标;导入Google Earth【转】
  20. gulp报错160

热门文章

  1. Java并发编程-ReentrantLock
  2. Android--手持PDA读取SD卡中文件
  3. 初探JAVA中I/O流(二)
  4. 小菜鸟学 MQ(三)
  5. Canvas识别相似图片
  6. Java-clone浅/深复制
  7. ios消息
  8. 让Jayrock插上翅膀(加入输入输出参数注释,测试页面有注释,下拉框可以搜索)
  9. Ext comboBox的remote和local的区别
  10. 利用Arraylist输入学生的成绩,求出平均分和总分。