Я создаю Tample Run, похожий на бесконечный раннер. Я могу успешно вращать камеру в плеере вместе, но я хочу, чтобы камера двигалась плавно, как в других играх.
Обратите внимание, что функция перемещения вызывается в методе обновления
Персонаж третьего лица (это тоже привязывается к игроку)
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=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;
}
А вот скрипт камеры
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));
}
Подробнее здесь: https://stackoverflow.com/questions/312 ... in-unity3d
Плавное вращение камеры в бесконечном бегуне на поворотах в Unity3d ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
CSS 3D изометрический куб - лица исчезают при определенных поворотах
Anonymous » » в форуме Javascript - 0 Ответы
- 0 Просмотры
-
Последнее сообщение Anonymous
-