Камера от 3-го лица

Различных вариантов реализации камеры от третьего лица можно найти много. Начиная от базового в самом Unity, и далее до бесконечности на различных тематических форумах. Добавлю свои 5 копеек в это разнообразие.

Скрипт CameraControl:

public GameObject _camera;

//Настройки камеры
private float x = 135f;
private float y = 45f;
private float distance = 3.0f;
private float minDist = 2.0f;
private float maxDist = 6.0f;
private float xSpeed = 250.0f;
private float ySpeed = 120.0f;
private float yMinLimit = 10f;
private float yMaxLimit = 60;

void Update() {
	if (Input.GetMouseButton(1)){
		x += (float)(Input.GetAxis("Mouse X") * xSpeed * 0.02);
		y -= (float)(Input.GetAxis("Mouse Y") * ySpeed * 0.02);
	distance += -(Input.GetAxis("Mouse ScrollWheel"));
	if (distance < minDist) distance = minDist;
	if (distance > maxDist) distance = maxDist;

	y = ClampAngle(y, yMinLimit, yMaxLimit);

	Quaternion rotation = Quaternion.Euler(y, x, 0);
	Vector3 position = (Vector3)(rotation * new Vector3(0.0f, 0.0f, -distance));

	_camera.transform.rotation = rotation;
	_camera.transform.position = position;

float ClampAngle (float angle, float min, float max) {
	if (angle < -360)
		angle += 360;
	if (angle > 360)
		angle -= 360;
	return Mathf.Clamp (angle, min, max);

Вращение камеры при зажатой ПКМ с ограничением угла подъема и опускания камеры. Отдаление и приближение камеры с помощью колёсика мыши, так же с ограничением по дальности.

Скачать пример (772)


28 thoughts on “Камера от 3-го лица

  1. You made some first rate factors there. I regarded on the web for the problem and located most individuals will go along with together with your website.

  2. There are some attention-grabbing closing dates on this article however I don抰 know if I see all of them heart to heart. There’s some validity however I will take maintain opinion until I look into it further. Good article , thanks and we want extra! Added to FeedBurner as well

  3. An impressive share, I simply given this onto a colleague who was doing somewhat analysis on this. And he the truth is bought me breakfast as a result of I found it for him.. smile. So let me reword that: Thnx for the treat! However yeah Thnkx for spending the time to debate this, I really feel strongly about it and love studying extra on this topic. If doable, as you turn out to be expertise, would you mind updating your blog with extra details? It is extremely useful for me. Large thumb up for this blog publish!

  4. I was more than happy to search out this net-site.I wanted to thanks for your time for this glorious read!! I definitely enjoying each little bit of it and I’ve you bookmarked to take a look at new stuff you blog post.

  5. I would like to express some appreciation to the writer for bailing me out of this instance. As a result of surfing around through the the web and coming across things that were not productive, I believed my entire life was done. Living without the answers to the problems you’ve sorted out as a result of this article content is a crucial case, and the ones that could have in a negative way affected my career if I had not noticed your website. The know-how and kindness in taking care of almost everything was valuable. I’m not sure what I would have done if I hadn’t encountered such a thing like this. I’m able to at this point look forward to my future. Thanks a lot so much for this specialized and effective help. I will not be reluctant to refer your blog to any individual who should receive assistance about this problem.

  6. I and also my pals ended up reviewing the great pointers located on your web site then the sudden came up with a terrible feeling I had not thanked the blog owner for those techniques. All of the guys came for this reason stimulated to learn them and already have honestly been tapping into these things. Thanks for truly being quite helpful and also for picking this kind of fantastic resources millions of individuals are really desirous to understand about. My very own honest apologies for not expressing gratitude to you earlier.

  7. My husband and i ended up being really lucky that Edward managed to round up his research via the ideas he gained from your very own web page. It is now and again perplexing to simply be offering facts that many people could have been making money from. And we also know we now have you to give thanks to for that. The most important illustrations you’ve made, the easy blog menu, the friendships you can help engender — it’s got everything powerful, and it’s facilitating our son and us know that this subject is interesting, which is highly pressing. Many thanks for everything!

  8. I have to convey my affection for your kind-heartedness supporting people who must have guidance on the theme. Your personal dedication to passing the solution up and down turned out to be rather significant and have always allowed women like me to arrive at their dreams. Your new valuable guide entails a whole lot to me and still more to my office workers. Warm regards; from each one of us.

  9. I would like to express my gratitude for your kind-heartedness giving support to those who need help on your field. Your real commitment to getting the message up and down appears to be really useful and has continuously allowed guys much like me to attain their pursuits. The invaluable help and advice entails a great deal a person like me and much more to my mates. Warm regards; from each one of us.

  10. I truly wanted to compose a brief word in order to appreciate you for all the great tips and tricks you are sharing on this site. My long internet look up has at the end been compensated with reputable strategies to exchange with my two friends. I would believe that we website visitors actually are unquestionably blessed to be in a fantastic community with many brilliant individuals with beneficial suggestions. I feel very much lucky to have discovered your web page and look forward to plenty of more awesome minutes reading here. Thanks once more for all the details.

  11. I actually wanted to compose a brief comment to appreciate you for these great points you are posting at this site. My extensive internet search has finally been paid with awesome content to share with my relatives. I ‘d mention that most of us readers are quite blessed to exist in a notable community with very many lovely professionals with insightful plans. I feel rather blessed to have encountered the website and look forward to many more amazing minutes reading here. Thank you again for everything.

  12. A powerful share, I simply given this onto a colleague who was doing a bit of evaluation on this. And he actually bought me breakfast as a result of I discovered it for him.. smile. So let me reword that: Thnx for the treat! However yeah Thnkx for spending the time to debate this, I feel strongly about it and love reading more on this topic. If attainable, as you grow to be expertise, would you thoughts updating your weblog with more details? It is highly useful for me. Huge thumb up for this weblog publish!

  13. I’m also writing to make you know what a terrific experience our princess had going through your site. She noticed a good number of things, not to mention what it is like to have an awesome teaching heart to have most people without difficulty fully grasp a number of problematic matters. You undoubtedly exceeded people’s expectations. Many thanks for giving the good, trusted, informative as well as easy tips about your topic to Julie.

  14. I want to show appreciation to this writer for bailing me out of this incident. Because of surfing around through the world wide web and seeing concepts that were not helpful, I thought my entire life was well over. Living devoid of the strategies to the problems you’ve solved by way of your main guideline is a critical case, as well as ones which might have in a negative way affected my entire career if I hadn’t noticed your web site. Your primary natural talent and kindness in touching everything was crucial. I am not sure what I would’ve done if I had not come upon such a stuff like this. I can also at this point look ahead to my future. Thanks for your time very much for this specialized and result oriented help. I will not be reluctant to endorse the sites to anyone who needs to have assistance about this topic.

  15. My wife and i ended up being quite more than happy that Michael managed to do his investigations with the ideas he obtained when using the blog. It’s not at all simplistic to just find yourself giving for free solutions other people might have been selling. And now we know we now have the blog owner to give thanks to because of that. These illustrations you have made, the easy site menu, the friendships you can give support to create — it is mostly superb, and it’s making our son in addition to us believe that the issue is amusing, and that’s exceedingly vital. Many thanks for all the pieces!

  16. Read reviews and was a little hesitant since I had already inputted my order. and it could be but thank god, I had no issues. prefer the received item in a timely matter, they are in new condition. you decide so happy I made the purchase. Will be definitely be purchasing again.
    cheap jordans https://www.realcheapjordan.com/

  17. По умолчанию камера расположена за спиной вашего персонажа, но вы всегда можете перейти в режим боя от 1-го лица.

Добавить комментарий

Ваш e-mail не будет опубликован.