【发布时间】:2015-07-07 18:43:55
【问题描述】:
我正在创建 tample run,就像无尽的跑步者一样,我可以成功地一起旋转播放器中的相机,但我希望相机像其他游戏一样平稳移动。 请注意在更新方法中调用移动函数
ThirdpersonCharecter(这也附加到玩家身上)
public void Move(bool left,bool right, bool crouch, bool jump)
{
if (right) {
switch (forwardDirection) {
case 1:
m_Rigidbody.velocity = new Vector3 (12f, 0, 0f);
break;
case 2:
m_Rigidbody.velocity = new Vector3 (0f, 0, -12f);
break;
case 3:
m_Rigidbody.velocity = new Vector3 (0f, 0, 12f);
break;
case 4:
m_Rigidbody.velocity = new Vector3 (-12f, 0, 0f);
break;
}
} else if (left) {
switch (forwardDirection) {
case 1:
m_Rigidbody.velocity = new Vector3 (-12f, 0, 0f);
break;
case 2:
m_Rigidbody.velocity = new Vector3 (0f, 0, 12f);
break;
case 3:
m_Rigidbody.velocity = new Vector3 (0f, 0, -12f);
break;
case 4:
m_Rigidbody.velocity = new Vector3 (12f, 0, 0f);
break;
}
} else {
switch (forwardDirection) {
case 1:
m_Rigidbody.velocity = new Vector3 (0f, 0f, 10f);
break;
case 2:
m_Rigidbody.velocity = new Vector3 (10f, 0f, 0f);
break;
case 3:
m_Rigidbody.velocity = new Vector3 (-10f, 0f, 0f);
break;
case 4:
m_Rigidbody.velocity = new Vector3 (0f, 0f, -10f);
break;
}
}
if (crouch && m_Animator.GetCurrentAnimatorStateInfo (0).IsName ("Run")) {
m_Crouching = true;
} else {
m_Crouching = false;
}
CheckGroundStatus();
if (!turn) {
UpdateAnimator (jump);
} else {
if(right)
{
turn = false;
Vector3 temp = transform.rotation.eulerAngles;
if(temp.y<269f){
temp.y=temp.y+90f; }
else {
temp.y=0;
}
transform.eulerAngles = temp;
switch (forwardDirection) {
case 1:
forwardDirection=2;
break;
case 2:
forwardDirection=4;
break;
case 3:
forwardDirection=1;
break;
case 4:
forwardDirection=3;
break;
}
}else if(left){
turn=false;
Vector3 temp=transform.rotation.eulerAngles;
if(temp.y>-269f){
temp.y=temp.y-90f; }
else {
temp.y=0;
}
transform.eulerAngles = temp;
switch (forwardDirection) {
case 1:
forwardDirection=3;
break;
case 2:
forwardDirection=1;
break;
case 3:
forwardDirection=4;
break;
case 4:
forwardDirection=2;
break;
}
}
}
right = false;
left = false;
}
void UpdateAnimator(bool jump)
{
if (jump) {
m_Animator.SetBool ("Jump", true);
} else {
m_Animator.SetBool ("Jump", false);
}
if (m_Crouching) {
m_Animator.SetBool ("Crouch", true);
count = 0;
}
else {
count +=1;
if(count>100)
m_Animator.SetBool ("Crouch", false);
}
}
public void OnAnimatorMove()
{
if (m_IsGrounded && Time.deltaTime > 0)
{
Vector3 v = (m_Animator.deltaPosition * m_MoveSpeedMultiplier) / Time.deltaTime;
// we preserve the existing y part of the current velocity.
v.y = m_Rigidbody.velocity.y;
m_Rigidbody.velocity = v;
}
}
public void setTurn(bool t){
turn = t;
}
这是 camara 脚本
void Start () {
Vector3 angles = transform.eulerAngles;
x = angles.x;
y = angles.y;
}
void LateUpdate () {
if(!target)
return;
y = target.eulerAngles.y;
// ROTATE CAMERA:
Quaternion rotation = Quaternion.Euler (x, y, 0);
transform.rotation = rotation;
// POSITION CAMERA:
transform.position = target.position - (rotation * Vector3.forward * distance + new Vector3(0,-targetHeight,0));
}
【问题讨论】:
-
关于游戏引擎
unity3d的问题请不要给unity标签。
标签: unity3d unityscript