allunity3d | Дата: Суббота, 20.03.2021, 21:29 | Сообщение # 1 |
Рядовой
Группа: Администраторы
Сообщений: 16
Статус: Offline
| Как установить unity3d ?
|
|
| |
javascriptlist | Дата: Воскресенье, 28.03.2021, 12:50 | Сообщение # 2 |
Рядовой
Группа: Пользователи
Сообщений: 2
Статус: Offline
| Нужен пример скрипта камеры для моей рпг игры. можно пример скрипта C# Добавлено (28.03.2021, 12:59) --------------------------------------------- Забыл дополнить Мне нужен ваш скрипт из урока Сергея Хоббитока 1 по рпг . Добавлено (28.03.2021, 13:00) --------------------------------------------- Скрипт MYTPS_Camera.cs Добавлено (28.03.2021, 13:09) --------------------------------------------- Ожидаю Добавлено (28.03.2021, 13:10) --------------------------------------------- Нужно
|
|
| |
seoloveup | Дата: Понедельник, 29.03.2021, 23:10 | Сообщение # 3 |
Рядовой
Группа: Пользователи
Статус: Offline
| Я когда смотрел видео ролик . Все там понятно , просто смотрите и пишите . Полезно будет на учитесь писать скрипты !
|
|
| |
obzorplay | Дата: Пятница, 30.04.2021, 21:09 | Сообщение # 4 |
Рядовой
Группа: Пользователи
Сообщений: 4
Статус: Offline
| Да не хотят писать держите Подарок Лентаи
using UnityEngine; using System.Collections;
public class MYTPS_PlayerCamera : MonoBehaviour { public bool IsAimed = false; public bool IsCrouched = false; public bool canControll = false; public bool LockCursor = true;
public Transform LookAt; public Transform MCamera; public Camera CameraObject; public Transform AimTarget;
public float targetHeight = 1.7f; public float distance = 4.0f; public float maxDistance = 4f; public float minDistance = 1f; public float xSpeed = 250.0f; public float ySpeed = 120.0f; public int yMinLimit = -80; public int yMaxLimit = 80; public int yAimMinLimit = -36; public int yAimMaxLimit = 58; public int zoomRate = 40; public float rotationDampening = 20f; public float zoomDampening = 5f;
public Vector3 Pivot = new Vector3(-0.32f, 0.11f, 1.14f); public Vector3 AimPivot = new Vector3(-0.21f, 0.03f, 0.29f); public Vector3 AimCrouchPivot = new Vector3(-0.27f, 0.16f, 0.3f);
public float AdjustAimUpAfter = -24f; public Vector3 AdjustAimUp = new Vector3(0f, -0.05f, -0.11f); public float AdjustAimDownAfter = 24f; public Vector3 AdjustAimDown = new Vector3(0f, -0.08f, -0.33f);
private float timer = 0.0f; public float bobbingSpeed = 0.18f; public float bobbingAmount = 0.2f; public float midpoint = 2.0f;
public float AimY { get { return this.yAim; } }
public float AimX { get { return this.xAim; } } private float x = 0.0f; private float y = 0.0f; private float currentDistance; private float desiredDistance; private float correctedDistance; private float yAim = 0.0f; private float xAim = 0.0f; private Vector3 diffPivot = Vector3.zero; private Vector3 AdjustAimVector = Vector3.zero; public bool freeRotation = false;
void Start() { LookAt = GameObject.Find("Target").transform; CameraObject = this.GetComponent<Camera>(); MCamera = transform; AimTarget = GameObject.Find("AimTarget").transform;
Vector3 angles = transform.eulerAngles; x = angles.x; y = 9;
currentDistance = distance; desiredDistance = distance; correctedDistance = distance;
if (!canControll) canControll = true; }
void Awake() { DontDestroyOnLoad(gameObject); }
void LateUpdate() {
if (!canControll) return;
// Don't do anything if target is not defined if (!LookAt) return;
ThirdPersonCamera(); }
void Update() { if (Input.GetKey(KeyCode.Escape)) LockCursor = false;
if (LockCursor) Screen.lockCursor = true; else Screen.lockCursor = false;
if (!canControll) return;
}
public void SetFreeRotation(bool free) { freeRotation = free; }
void ThirdPersonCamera() { if (!IsAimed) { y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f; y = ClampAngle(y, yMinLimit, yMaxLimit);
yAim = y; } else { float aimDirVert = Input.GetAxis("Mouse Y"); yAim -= aimDirVert * ySpeed * 0.010f; yAim = ClampAngle(yAim, yAimMinLimit, yAimMaxLimit); }
float aimDirHor = Input.GetAxis("Mouse X"); xAim -= aimDirHor * xSpeed * 0.010f;
float targetRotationAngle = LookAt.eulerAngles.y; float currentRotationAngle = MCamera.eulerAngles.y;
if (!freeRotation) x = Mathf.LerpAngle(currentRotationAngle, targetRotationAngle, rotationDampening * Time.deltaTime); else x = xAim;
Quaternion rotation = Quaternion.identity; if(!IsAimed) rotation = Quaternion.Euler(y, x, 0); else rotation = Quaternion.Euler(yAim, x, 0);
desiredDistance -= Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * zoomRate * Mathf.Abs(desiredDistance); desiredDistance = Mathf.Clamp(currentDistance, minDistance, maxDistance); correctedDistance = desiredDistance;
AdjustCameraAim();
Vector3 selectedPivot = Vector3.zero;
if (IsAimed) { if (!IsCrouched) selectedPivot = AimPivot; else selectedPivot = AimCrouchPivot; } else selectedPivot = Pivot;
diffPivot = Vector3.Lerp(diffPivot, selectedPivot, 0.1f);//
Vector3 position = LookAt.position - (rotation * (diffPivot + AdjustAimVector) * desiredDistance + new Vector3(0, -targetHeight, 0));
RaycastHit collisionHit; Vector3 trueTargetPosition = new Vector3(LookAt.position.x, LookAt.position.y + targetHeight, LookAt.position.z);
bool isCorrected = false;
//Debug.DrawLine(trueTargetPosition, position, Color.red); if (Physics.Linecast(trueTargetPosition, position, out collisionHit)) { if (collisionHit.collider && collisionHit.collider.tag != "Player" && collisionHit.collider.tag != "MainCamera") { position = collisionHit.point; correctedDistance = Vector3.Distance(trueTargetPosition, position); isCorrected = true; } }
currentDistance = !isCorrected || correctedDistance > currentDistance ? correctedDistance : currentDistance; //Mathf.Lerp(currentDistance, correctedDistance, Time.deltaTime * zoomDampening) : correctedDistance;
MCamera.rotation = rotation; MCamera.position = position;
AimTarget.position = MCamera.position + MCamera.forward * 10f; }
Vector3 CameraBob() { float waveslice = 0.0f; float horizontal = 0f; float vertical = Input.GetAxis("Vertical"); Vector3 cSharpConversion = MCamera.position; if (Mathf.Abs(vertical) == 0) { timer = 0.0f; } else { waveslice = Mathf.Sin(timer); timer = timer + bobbingSpeed; if (timer > Mathf.PI * 2) { timer = timer - (Mathf.PI * 2); } } if (waveslice != 0) { float translateChange = waveslice * bobbingAmount; float totalAxes = Mathf.Abs(horizontal) + Mathf.Abs(vertical); totalAxes = Mathf.Clamp(totalAxes, 0.0f, 1.0f); translateChange = totalAxes * translateChange; cSharpConversion.y = midpoint + translateChange; } else { cSharpConversion.y = midpoint; }
return cSharpConversion; }
private void AdjustCameraAim() { if (AdjustAimUpAfter != 0f && AdjustAimUp != Vector3.zero) { if (yAim < AdjustAimUpAfter) { AdjustAimVector = Vector3.Lerp(AdjustAimVector, AdjustAimUp, 0.1f); } else { AdjustAimVector = Vector3.Lerp(AdjustAimVector, Vector3.zero, 0.08f); } }
if (AdjustAimUpAfter != 0f && AdjustAimUp != Vector3.zero) { if (yAim > AdjustAimDownAfter) { AdjustAimVector = Vector3.Lerp(AdjustAimVector, AdjustAimDown, 0.1f); } else { AdjustAimVector = Vector3.Lerp(AdjustAimVector, Vector3.zero, 0.08f); } } } private static float ClampAngle(float angle, float min, float max) { if (angle < -360) angle += 360; if (angle > 360) angle -= 360;
return Mathf.Clamp(angle, min, max); } }
|
|
| |