Тёмный

(03) Stealth Game - Camera Collision and Clipping (Unity, C#) 

Code With Ajay
Подписаться 8 тыс.
Просмотров 10 тыс.
50% 1

[Third Person Camera Collision and Clipping Fix] Ever wanted to make an epic stealth game from scratch and learn while you do so? Well... you've come to the right place, today we'll be working on a third person camera collision script which will allow the camera to slide and collide and adjust it's view in order to always be able to see the player. It's very nice and can work with any game. All made in Unity and C#.
____________________________________________________________
Join me on --
✄ / codewithajay ✄
----- LETS TRY AND HIT : 70 LIKES ✌ ---------
★ Upcoming Videos :
Building a Self Driving car With Neural Networks ❤
Development Log #2 ❤
See the Finished Product of todays episode : 0:00 - 1:15
[More chapter markers down below]
See an awesome development log, where I build an open world game from scratch using Unity : • Video
The next part is even better and in order for you to see it you have to subscribe and tap that bell icon to be notified : www.youtube.co...
Links :
----------------------------------------------------------------------------------------------------
[FILES] Part 3 Project (w/ all scripts + scenes): corneey.com/wsBMOl
[VIDEO] Previous Part (Node Editor) : • (02) Stealth Game - Cu...
[VIDEO] Part 1 (Character Controller) : • (01) Stealth Game - Cu...
If you enjoyed this video please COMMENT down bellow exactly what YOU would like to see in the next episode and I'll add it in and shout you out!! I need your contribution in order for me to make this channel bigger and better for everyone ;)
----------------------------------------------------------------------------------------------------
If you want to see something next episode, comment down below but if you don't I have some great ideas myself.
CURRENT VIDEO IDEA FROM : 'Mind Pixel'
Help make this channel bigger by tapping that like button it would really help me out :) Thank you everyone for your support.
Parts of the Video :
-------------------------------------------------------
What is this about : 0:00 - 1:15
System Explanation : 1:15 : 5:04
Modifying + Adding Variables : 5:04 - 9:49
Writing the main system : 9:49 - 25:15
Final Test + Corridors : 25:15 - 28:40
Finished Product : 0:00 - 1:15
-------------------------------------------------------
Video Description -
This video is mainly focused on handling the camera's collisions and clipping issue, when our camera revolves around the player it sometimes goes through the walls and we are unable to see the player, this video will address this problem with a variety of techniques.
Series Description -
This series was built to be an entertaining way of learning Unity while making an incredible game, you will learn how to make complex AI behaviour and write complex scripts such as custom character controllers w/ custom handled collision and slopes and Editor Code to control behaviour. All being essential skills to being a Pro Unity Developer.

Опубликовано:

 

6 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 59   
@tommyyodergamecreator
@tommyyodergamecreator 5 лет назад
You, sir, are a lifesaver. I have been trying to get a camera clipping script to work for a roll-a-ball game back in 2017. Nothing seemed to work until I discovered this video tonight. This is working perfectly to make the camera not go through the walls!
@batchprogrammer108
@batchprogrammer108 5 лет назад
I'm so happy that it worked, good luck with your game :)
@tommyyodergamecreator
@tommyyodergamecreator 5 лет назад
Tommy Yoder Thank you! Got a question that I am trying to figure out. So, the camera clipping is working great. However, the script is not allowing the sphere to rotate when moving the player. Going to rewatch the video again to see if I did something wrong (tend to do this at times,) but do you know what could be the issue? If I uncheck the camera script the sphere when moved will rotate as intended. Odd I know. Thank you again!!!
@batchprogrammer108
@batchprogrammer108 5 лет назад
@@tommyyodergamecreator Well inside the script I do manipulate the rotation of the target, so this may be your issue?
@tommyyodergamecreator
@tommyyodergamecreator 5 лет назад
Ok gotcha. This does help to debug the rotation. Thank you again!
@batchprogrammer108
@batchprogrammer108 5 лет назад
@@tommyyodergamecreator Sorry I couldn't be of more help, hope you can fix it :)
@rustedknight_
@rustedknight_ 4 года назад
Your attitude in the first 1 minute has already gotten me to subscribble.
@mindpixel523
@mindpixel523 6 лет назад
Wow! This is the best setup I've seen for a Camera Collision system! Nice job AJ! I can't wait for your next set of videos! I have some more ideas I'll make sure to suggest again!
@batchprogrammer108
@batchprogrammer108 6 лет назад
Hey, thank you very much! Can't wait to hear your other suggestions :D
@batchprogrammer108
@batchprogrammer108 6 лет назад
Hey just wanted to say thank you for supporting me in the creation of these videos it's been awesome! :)
@printerestingco5639
@printerestingco5639 4 года назад
This is the best tutorial for this feature! I've seen few doing the same, only this works perfectly! Thank you! You're awesome!
@Spencer_Hill
@Spencer_Hill 5 лет назад
Awesome series so far! Would be cool to see something to account for small walls/obstacles (like auto climbing) since at the moment the character just automatically snaps up top of any small objects.
@mauriciom8539
@mauriciom8539 6 лет назад
meu deus, sou do brasil e descobri seu canal agora, preciso terminar um trabalho de conclusão de curso e acredito que seus vídeos me darão muito apoio. Obrigado e ótimo trabalho.
@batchprogrammer108
@batchprogrammer108 6 лет назад
Good luck with your course, you're very welcome!
@humptydumpty7935
@humptydumpty7935 6 лет назад
It's very interesting to learn.I am really enjoying it :) Can you do it using Mecanim ?
@radomiami
@radomiami 4 года назад
Epic camera!
@minus2486
@minus2486 6 лет назад
Finally work after I try many tutorial about camera collision Love u man
@batchprogrammer108
@batchprogrammer108 6 лет назад
Glad it worked for you :)
@11monkeyking
@11monkeyking 6 лет назад
My brain is teaming with ideas. From reading some of convos below, some of those ideas possibly may already implemented, so I will refrain from some of them for now. However, I was wondering if you could add a "double jump" snippet in one of the upcoming videos? In my current project, I am attempting to have some animations fire off from an event if doublejump is true. Great stuff! So glad I found this channel.
@batchprogrammer108
@batchprogrammer108 6 лет назад
Thanks for the Idea Chris! I will add this to the list and will add it as soon as I can :)
@TheLeontheking
@TheLeontheking 6 лет назад
man I like the cam! Quite action-like ;)
@Max-up8vj
@Max-up8vj 5 лет назад
underrated content
@Nitikk_A
@Nitikk_A 3 года назад
Hello AJ, Can you guide me if there's a way we can reduce the free movement of the camera, since I am implementing this with touch controls and on a small drag, the camera over moves. I am looking for a camera movement like PUBG and your camera collisions are the most precise one I've come across. Looking forward to your reply!
@anthonycontrevilliers4352
@anthonycontrevilliers4352 6 лет назад
Great great tutorial ! It help me for a class project !
@batchprogrammer108
@batchprogrammer108 6 лет назад
Thank you! Good luck :)
@nerditstudios3457
@nerditstudios3457 5 лет назад
Great tutorial. I will definitely recommend this video to others.
@batchprogrammer108
@batchprogrammer108 5 лет назад
Highly Appreciate it, I'm glad you enjoyed it! :)
@guilhermesombra6171
@guilhermesombra6171 5 лет назад
Awsome video, man. I have a question, Is there a way to fix the camera going on top of the player because of small walls? Every time the player drop from a small step of a stair the camera goes right up. One more thing, are you planning to show us how to make alternative cameras, like free-look while moving and fixed while aiming?
@joaobaltieriArt
@joaobaltieriArt 4 года назад
I'm having a little delay and offset with the camera position when starts and stops the rotation, like it shows in your video, but it's more intense. I've tried some different values for the mouse sensitivity and rotation smooth time, but nothing is working... In the first camera controller code this is not happening. Can you imagine why? Anyway, thanks for the awesome video. Helped a lot! ;)
@PakGrantChristie
@PakGrantChristie 6 лет назад
Enjoyed this. I'd ike to learn how to implement a Mario style jump with this character. Keep up your great work.
@batchprogrammer108
@batchprogrammer108 6 лет назад
Hey Grant, thank you for the idea, I will implement it in my next episode. :) Just to clarify when you say 'Mario style jump' do you mean when you hold the spacebar you jump higher and when you tap it you jump lower?
@PakGrantChristie
@PakGrantChristie 6 лет назад
I like that idea too. It would be awesome to see how to do that! I was thinking about how to make then character fall back to earth quicker. So it jumps smoothly as your have it now but snaps an bit quicker back to the ground. e.g. using System.Collections; using System.Collections.Generic; using UnityEngine; public class MarioJump : MonoBehaviour { public float jumpVelocity = 15f; public float jumpMultiplier = .01f; public float fallMultiplier = 0f; // Use this for initialization public Rigidbody rb; void Start () { rb = GetComponent (); } // Update is called once per frame void Update () { if (Input.GetButtonDown ("Jump")){ rb.velocity = Vector3.up * jumpVelocity; } if (rb.velocity.y > 0 && !Input.GetButtonDown ("Jump")) { rb.velocity += Vector3.up * Physics.gravity.y * jumpMultiplier * Time.deltaTime; } else if (rb.velocity.y < 0) { rb.velocity += Vector3.up * Physics.gravity.y * fallMultiplier * Time.deltaTime; } } }
@batchprogrammer108
@batchprogrammer108 6 лет назад
Grant Christie Oh okay I understand now I’ll implement it into the video right away :) Thank you very much for the idea
@PakGrantChristie
@PakGrantChristie 6 лет назад
AJTech thanks. I really hope many others see the value of what you are doing. I've paid for courses that aren't as interesting or thorough as this. I'm putting you up with Brackeys for quality of content. I am staying glued to this channel.😄
@batchprogrammer108
@batchprogrammer108 6 лет назад
Wow, thank you very much Grant, your words mean a lot and have given me more motivation to continue uploading =D
@blablabla1196
@blablabla1196 4 года назад
Hey man thanks for all that you do! One thing I noticed is that at 22:50, inside the CollisionCheck method, there is an IF statement starting with Vector3.Distance that never has any THEN code inside of it. And from 22:50 till the end of the video, it never gets changed. Isn't that an issue? Cause my camera makes my player jitter a little bit, thought maybe that's why. Any ideas? UPDATE: Actually just realized its the returnSpeed in the Inspector. When I set it to anything below 55, the player jitters. Anything above 55 its smooth. But of course that makes the return speed way too high to the point where its changing its angles in an instant.
@zandrewsonnemaker5579
@zandrewsonnemaker5579 6 лет назад
Hey AJ, it's funny that you presented that slanted corridor example at the end there. I have the same situation in my demo area but I have an issue with the current character controller involving this. If I walk at the underside of that slope, I pop down through the floor! Is this something that you've already addressed later? I'm curious to know what methods there are of preventing this. I'm sure simply not allowing a character to proceed if a certain raycast shows an undesirable headspace but I feel like there's probably other options, let me know!
@batchprogrammer108
@batchprogrammer108 6 лет назад
Hey Zandrew, I have tried a lot of methods to try and fix the corridor issue with the player controller which have not been satisfactory because they can detect random objects as corridors and don't help much at all, one option is guess is to sphere/capsule cast forward and check the distance of the hit point, if it is a very small amount we could decrease the velocity in that direction. But your raycast idea, if you could elaborate how you would make it work then I will certainly add it in the next video that I post and give you all the credit :) Have a great day :)
@zandrewsonnemaker5579
@zandrewsonnemaker5579 6 лет назад
AJTech actually a sphere cast makes more sense, the other option is to just physically block the player with an invisible wall in those instances right- Meh, might not be worth covering of that's the solution. I'm gonna dig around
@bennyphoe6209
@bennyphoe6209 4 года назад
Hello is there any way to convert a skinned mesh renderer to a mesh renderer to be used as target renderer? My player object has 3 materials all under skinned mesh renderer and i cant change the object property from opaque to fade..
@DJLKM1
@DJLKM1 5 лет назад
Just a thought, why do we shoot a ray from the player to the camera, i was thinking of the other way round. Anyhow, great tutorial again!.
@batchprogrammer108
@batchprogrammer108 5 лет назад
Right, I also thought about this technique at the start however it doesn't work as well because when you shoot a ray from the player to the camera you can get the optimal viewing position however if you shoot from the camera to the player you will not be able to find the best place to see the player from, you should change the code a bit and see how it changes things ;). Thank you again, glad you are enjoying this series :D
@gnightrow4020
@gnightrow4020 6 лет назад
Is there any reason why you open a statement like { } instead of { }
@kieranmacpherson2860
@kieranmacpherson2860 6 лет назад
gNightrow It’s really Personal preference. I prefer to use { } Only because it makes my scripts look more organized. But it has no effect on the outcome of the script.
@jomarpepito4197
@jomarpepito4197 6 лет назад
why i can't put my player to target renderer?
@jomarpepito4197
@jomarpepito4197 6 лет назад
why did I get an error on Header when I type " [Header("Collision Vars")]" and the error says "Attribute Header is not valid, It is only valid on field declarations"?
@batchprogrammer108
@batchprogrammer108 6 лет назад
Its because that has to be written on a line immediately before the declaration of a public variable. There can be no gap lines.
@mindpixel523
@mindpixel523 6 лет назад
Can you confirm if this works on Unity 2018.1.6? I copied everything exactly but whenever the camera collides it shakes like crazy back and forth. Any ideas?
@batchprogrammer108
@batchprogrammer108 6 лет назад
This should be working in any version, the problem may be occurring if you have the wrong update functions ? Are you on LateUpdate() ?
@mindpixel523
@mindpixel523 6 лет назад
Okay! I got it working. The only issue I have for me is on my terrain with hills the camera can clip through the floor. Would I shoot another ray cast down at the floor from the camera to set a max limit from the floor? I wonder if it's possible to use a SphereCast to limit and collide in any direction?
@batchprogrammer108
@batchprogrammer108 6 лет назад
Both of those options would be completely fine! But you may have to modify the current code to work in conjunction with any other systems you place in. For other's benefit would you mind sharing how you got the camera shaking to work, just in case anyone else has the same issue?
@lobsangwhite
@lobsangwhite 6 лет назад
I tried to build an offset using a vector3 to place my player a little bit at left (Like mostly thirdperson games) but I got a problem with the raycast, it's hitting different each side.After try a lots ways I can't realize this on my own, can you help me?.Btw, if someone needs a really functional camera system I hope they find this video, it's a pitty you stop to posting.
@batchprogrammer108
@batchprogrammer108 6 лет назад
Hmm I'm not quite sure what the problem is, if you email me a zip of the files you have currently to - ajays.workemail@gmail.com then I will diagnose the problem and send it back to you. Just reply to this comment when you have emailed it. And yeah I'm sorry I'm slightly busy on another project but when I finish I'll be back on this and we have a lot of new ideas to implement! :)
@lobsangwhite
@lobsangwhite 6 лет назад
Thanks AJ you answer faster than I was expecting, I was going to send you a files package (I didn't), the problem was I was offsetting the camera, when I offset the camera I get a "Trembling" effect bc of camera is updating character position always, and if I offset the character it doesn't make sense bc th camera is always behind. Either way I can't to do what I want so far, not while camera spinning around the character, I tried deleting where you make eulerangles e.x = 0 but character movement screwed up, so I need to figure how to do it.
@batchprogrammer108
@batchprogrammer108 6 лет назад
This sounds like an interesting aspect that I would like to implement to this series, I will work on this in the next episode + I will be doing over the shoulder third person aiming as well if that will be of any help to you. :) The next episode will come out soon :)
Далее
(04) Stealth Game - Field of View (Unity, C#)
22:24
Просмотров 24 тыс.
20 Advanced Coding Tips For Big Unity Projects
22:23
Просмотров 187 тыс.
THIRD PERSON MOVEMENT in Unity
21:05
Просмотров 1,4 млн
An Aseprite Crash Course In 30 Minutes
31:47
Просмотров 1,1 млн
How do non-euclidean games work? | Bitwise
14:19
Просмотров 2,4 млн
Third Person Camera System using Cinemachine in Unity
19:07
How to ACTUALLY get into Gamedev
14:01
Просмотров 729 тыс.
Better Jumping in Unity With Four Lines of Code
12:47
Просмотров 822 тыс.