Unity3d 角色转身在向前走的脚本
2012-12-07 15:34
441 查看
var targetTransform: Transform;
var rotationSpeed : float=1.0;
var canRun=false;
var speed : float = 1.0;
function Update ()
{
var direction:Vector3=targetTransform.position - transform.position;
direction.y=0;
transform.rotation = Quaternion.RotateTowards (transform.rotation, Quaternion.LookRotation(direction), rotationSpeed);
//transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(direction), 2);
print(transform.rotation);
if (transform.rotation.eulerAngles .y == Quaternion.LookRotation(direction).eulerAngles.y)
{
canRun=true;
}
if (canRun == true)
{
var controller : CharacterController = GetComponent(CharacterController);
var forward : Vector3 = transform.TransformDirection(Vector3.forward);
var curSpeed : float = speed ;
var dist = Vector3.Distance(targetTransform.position, transform.position);
if (dist >= 2)
{
controller.SimpleMove(forward * curSpeed);
}
}
}
---------------------------------------------------------------------
var targetTransform: Transform;
var rotationSpeed : float=5;
var direction:Vector3;
function Update () {
direction=targetTransform.position-transform.position;
direction.y=0;
var angle = Vector3.Angle(direction, transform.forward);
transform.rotation = Quaternion.RotateTowards (transform.rotation, Quaternion.LookRotation(direction), rotationSpeed);
if(angle<5)
transform.position.x+=-0.1;
}
var rotationSpeed : float=1.0;
var canRun=false;
var speed : float = 1.0;
function Update ()
{
var direction:Vector3=targetTransform.position - transform.position;
direction.y=0;
transform.rotation = Quaternion.RotateTowards (transform.rotation, Quaternion.LookRotation(direction), rotationSpeed);
//transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(direction), 2);
print(transform.rotation);
if (transform.rotation.eulerAngles .y == Quaternion.LookRotation(direction).eulerAngles.y)
{
canRun=true;
}
if (canRun == true)
{
var controller : CharacterController = GetComponent(CharacterController);
var forward : Vector3 = transform.TransformDirection(Vector3.forward);
var curSpeed : float = speed ;
var dist = Vector3.Distance(targetTransform.position, transform.position);
if (dist >= 2)
{
controller.SimpleMove(forward * curSpeed);
}
}
}
---------------------------------------------------------------------
var targetTransform: Transform;
var rotationSpeed : float=5;
var direction:Vector3;
function Update () {
direction=targetTransform.position-transform.position;
direction.y=0;
var angle = Vector3.Angle(direction, transform.forward);
transform.rotation = Quaternion.RotateTowards (transform.rotation, Quaternion.LookRotation(direction), rotationSpeed);
if(angle<5)
transform.position.x+=-0.1;
}
相关文章推荐
- Unity3D Player角色移动控制脚本——转载
- Unity3d 实现鼠标左键点击地形使角色移动到指定地点[脚本]
- unity3d学习笔记(四)--自定义角色控制脚本及平滑转身
- Unity3D中角色的动画脚本的编写(一)
- [脚本] Unity3d 实现鼠标左键点击地形使角色移动到指定地点
- Unity3d 实现鼠标左键点击地形使角色移动到指定地点[脚本]
- Unity3D Player角色移动控制脚本
- unity3d 让角色运动之使用脚本(另一个方法为勾选Apply Root motion)
- Unity3D中角色的动画脚本的编写(二)
- Unity3D Player角色移动控制脚本
- Unity3D中角色的动画脚本的编写(一)
- Unity3d中角色的动画脚本的编写
- Unity3D中角色的动画脚本的编写(一)
- Unity3D中角色的动画脚本的编写(二)
- Unity3D中角色的动画脚本的编写
- Unity3D中角色的动画脚本的编写
- (转) [教程] Unity3D中角色的动画脚本的编写(一)
- Unity3D Player角色移动控制脚本
- Unity3d摄像机跟随角色移动脚本
- Unity3D Player角色移动控制脚本