Движение камеры при хотьбе и беге
skarb Дата: Пт, 11 Ноя 2011, 13:32 | Сообщение # 1
Сообщений: 42
Награды:
0
Репутация:
2
Статус: Offline
Как реализовать движение камеры при хотьбе, беге. Симулировать хотьбу чтобы камера перемещалась влево в вправо или поворачивалась в лево, впрао. Пробывал трансформ камеры ени хр.на не получается. Помогите плиз.
[img]http://img208.imageshack.us/img208/460/suwgb.gif[/img]
Сообщение Как реализовать движение камеры при хотьбе, беге. Симулировать хотьбу чтобы камера перемещалась влево в вправо или поворачивалась в лево, впрао. Пробывал трансформ камеры ени хр.на не получается. Помогите плиз. Автор - skarb Дата добавления - 11 Ноя 2011 в 13:32
Tibers Дата: Пт, 11 Ноя 2011, 13:57 | Сообщение # 2
Сообщений: 93
Награды:
3
Репутация:
58
Статус: Offline
Вот скрипт Code
using UnityEngine; public class Camera_FPS : MonoBehaviour { public Vector2 rotationLimit; //Limit for the vertical rotation of the camera. X is higher limit, Y is lower limit. public float rotationSpeed = 600.0f; //Vertical rotation speed of the camera public bool invertY = true; //Invert vertical rotation public bool headBobEnabled = true; //Enables/disables head bobbing public Vector2 headBobDistance = new Vector2(0.2f, 0.3f); //The distance the camera travels in the y-axis for the headBobbing effect public float headBobSpeed = 5.0f; //Speed at which the player's head bobs private Vector3 initialLocalPos; //Starting local y-position of camera private float rot; //Stores the rotation value incremented by mouse movement in the y-axis private Transform t; //Reference to the transform component of the game object public void Awake() { t = transform; //Cache transform component initialLocalPos = t.localPosition; //Store initial local position of the camera } public void Update () { //Update rotation rot += Input.GetAxis("Mouse Y") * rotationSpeed * ((invertY) ? -1 : 1) * Time.deltaTime; if(rot < rotationLimit.y) //Check for lower limit rot = rotationLimit.y; if(rot > rotationLimit.x) //Check for upper limi rot = rotationLimit.x; t.localRotation = Quaternion.AngleAxis (rot, Vector3.right); //Apply rotation to transform //Head bobbing if(headBobEnabled) { //Calculate percentage of blend between stationary and bobbing camera positions float percentage = Mathf.Min(1, Mathf.Abs(Input.GetAxis("Vertical")) + Mathf.Abs(Input.GetAxis("Horizontal"))); //Calculate desired x position float desiredPosX = initialLocalPos.x + headBobDistance.x * Mathf.Sin(Time.time * headBobSpeed + Mathf.PI/2); //Blend between stationary and desired x position float newX = (initialLocalPos.x * (1 - percentage)) + (desiredPosX * (percentage)); //Calculate desired y position float desiredPosY = initialLocalPos.y + headBobDistance.y * Mathf.Sin(Time.time * 2 * headBobSpeed); //Blend between stationary and desired y position float newY = (initialLocalPos.y * (1 - percentage)) + (desiredPosY * (percentage)); t.localPosition = new Vector3( newX, newY, t.localPosition.z); } } }
Скрипты не под спойлер нужно прятать а размещать используя тег code! (Dekterev)
[img]http://i.imgur.com/Muw4o.png[/img]
Сообщение отредактировал Dekterev - Сб, 12 Ноя 2011, 00:55
Сообщение Вот скрипт Code
using UnityEngine; public class Camera_FPS : MonoBehaviour { public Vector2 rotationLimit; //Limit for the vertical rotation of the camera. X is higher limit, Y is lower limit. public float rotationSpeed = 600.0f; //Vertical rotation speed of the camera public bool invertY = true; //Invert vertical rotation public bool headBobEnabled = true; //Enables/disables head bobbing public Vector2 headBobDistance = new Vector2(0.2f, 0.3f); //The distance the camera travels in the y-axis for the headBobbing effect public float headBobSpeed = 5.0f; //Speed at which the player's head bobs private Vector3 initialLocalPos; //Starting local y-position of camera private float rot; //Stores the rotation value incremented by mouse movement in the y-axis private Transform t; //Reference to the transform component of the game object public void Awake() { t = transform; //Cache transform component initialLocalPos = t.localPosition; //Store initial local position of the camera } public void Update () { //Update rotation rot += Input.GetAxis("Mouse Y") * rotationSpeed * ((invertY) ? -1 : 1) * Time.deltaTime; if(rot < rotationLimit.y) //Check for lower limit rot = rotationLimit.y; if(rot > rotationLimit.x) //Check for upper limi rot = rotationLimit.x; t.localRotation = Quaternion.AngleAxis (rot, Vector3.right); //Apply rotation to transform //Head bobbing if(headBobEnabled) { //Calculate percentage of blend between stationary and bobbing camera positions float percentage = Mathf.Min(1, Mathf.Abs(Input.GetAxis("Vertical")) + Mathf.Abs(Input.GetAxis("Horizontal"))); //Calculate desired x position float desiredPosX = initialLocalPos.x + headBobDistance.x * Mathf.Sin(Time.time * headBobSpeed + Mathf.PI/2); //Blend between stationary and desired x position float newX = (initialLocalPos.x * (1 - percentage)) + (desiredPosX * (percentage)); //Calculate desired y position float desiredPosY = initialLocalPos.y + headBobDistance.y * Mathf.Sin(Time.time * 2 * headBobSpeed); //Blend between stationary and desired y position float newY = (initialLocalPos.y * (1 - percentage)) + (desiredPosY * (percentage)); t.localPosition = new Vector3( newX, newY, t.localPosition.z); } } }
Скрипты не под спойлер нужно прятать а размещать используя тег code! (Dekterev) Автор - Tibers Дата добавления - 11 Ноя 2011 в 13:57
Скептик Дата: Сб, 12 Ноя 2011, 22:28 | Сообщение # 3
Мыслитель
Сообщений: 5860
Награды:
48
Репутация:
1731
Статус: Offline
Я анимацию создал зацикленную. Ничуть не хуже.
Фанат игр Max Payne и Fahrenheit.
Сообщение Я анимацию создал зацикленную. Ничуть не хуже. Автор - Скептик Дата добавления - 12 Ноя 2011 в 22:28
123_XanteR_456 Дата: Вс, 13 Ноя 2011, 15:58 | Сообщение # 4
Сообщений: 169
Награды:
0
Репутация:
35
Статус: Offline
Скептик , а по производительности? Анимация ведь быстрее?
Неплохо знаю JavaScript(Unity3D API) =)
Сообщение Скептик , а по производительности? Анимация ведь быстрее?Автор - 123_XanteR_456 Дата добавления - 13 Ноя 2011 в 15:58
Левша Дата: Вс, 13 Ноя 2011, 17:10 | Сообщение # 5
Черный Волк
Сообщений: 7257
Награды:
30
Репутация:
3313
Статус: Offline
Quote (123_XanteR_456 )
Анимация ведь быстрее?
Откуда такая информация?
X.cor.R (Prologue)
Сообщение Quote (123_XanteR_456 )
Анимация ведь быстрее?
Откуда такая информация?Автор - Левша Дата добавления - 13 Ноя 2011 в 17:10
123_XanteR_456 Дата: Вс, 13 Ноя 2011, 17:27 | Сообщение # 6
Сообщений: 169
Награды:
0
Репутация:
35
Статус: Offline
Левша , не не) Это вопрос!
Неплохо знаю JavaScript(Unity3D API) =)
Сообщение Левша , не не) Это вопрос!Автор - 123_XanteR_456 Дата добавления - 13 Ноя 2011 в 17:27
Левша Дата: Вс, 13 Ноя 2011, 22:01 | Сообщение # 7
Черный Волк
Сообщений: 7257
Награды:
30
Репутация:
3313
Статус: Offline
На самом деле быстрее процедурная анимация.
X.cor.R (Prologue)
Сообщение На самом деле быстрее процедурная анимация. Автор - Левша Дата добавления - 13 Ноя 2011 в 22:01
Скептик Дата: Пн, 14 Ноя 2011, 00:49 | Сообщение # 8
Мыслитель
Сообщений: 5860
Награды:
48
Репутация:
1731
Статус: Offline
Quote (123_XanteR_456 )
Скептик, а по производительности? Анимация ведь быстрее?
Не имел возможности сравнить.
Фанат игр Max Payne и Fahrenheit.
Сообщение Quote (123_XanteR_456 )
Скептик, а по производительности? Анимация ведь быстрее?
Не имел возможности сравнить.Автор - Скептик Дата добавления - 14 Ноя 2011 в 00:49