Тёмный

Custom Character Controller in Unity from Scratch (C#) 

AJTech
Подписаться 8 тыс.
Просмотров 27 тыс.
50% 1

THE LATEST VERSION : • (01) Stealth Game - Cu...
Join me on --
✄ codewithajay.com ✄ [DEV LOG WEBSITE]
✄ / codewithajay ✄ [TWITTER]
✄ / codewithajay ✄ [FACEBOOK]
----- LETS TRY AND HIT : 70 LIKES ✌ ---------
★ Upcoming Videos :
- Building a Self Driving car With Neural Networks ❤
- Development Log #2 ❤
See an awesome development log, where I build an open world game from scratch using Unity : • Video
This tutorial will help you create a fully functional character controller in Unity from scratch. Features of this controller include : Highly Customisable Values, Jumping, Movement, Slope Navigation, Object Collision Detection+Reaction and more all in one video. Enjoy and leave a like if you enjoyed.
If you want the latest version of this script (Not script in video, possibility that the current configuration of the script won't work for you ) : pastebin.com/8MTDuNwr

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

 

3 окт 2017

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 52   
@khajiit5556
@khajiit5556 6 лет назад
Khajit welcomes you! May your road lead you to warm sands!
@batchprogrammer108
@batchprogrammer108 6 лет назад
Thank you very much :)
@menatrs1
@menatrs1 4 года назад
What is that supposed to mean? Warm sands hurt your feet!
@janwagner3020
@janwagner3020 3 года назад
@@menatrs1 Skyrim
@TheLeontheking
@TheLeontheking 6 лет назад
nice I didn't know about the headers and the regions! and well, the rest is extremely useful as well!!
@batchprogrammer108
@batchprogrammer108 6 лет назад
I'm happy that this was useful for you! :D
@TheLeontheking
@TheLeontheking 6 лет назад
definitely!! Great tut and you are funny :D one tip for improvement: would be cool if you maximized your coding window in future vids, because when I watch this on my laptop screen it gets really hard to read the code ;)
@batchprogrammer108
@batchprogrammer108 6 лет назад
Ahh! I apologize for that, thanks for the feedback! :) Thank you!
@TheStrandedMoose
@TheStrandedMoose 5 лет назад
Hey dude thanks for the tutorial! I have everything working except the jump.. It just clicks up one frame instantly if I try to jump and I'm not sure why. I copied your code verbatim (for jump and gravity) but I can't seem to get it working, even without movement code
@roryedmonds9415
@roryedmonds9415 4 года назад
Will i be able to use this with a kinematic rigidbody?
@thecsharpdude2190
@thecsharpdude2190 4 года назад
Do you reccomend this or the newer version? I am making an Adventure/RPG type game
@matthewwoodle6603
@matthewwoodle6603 4 года назад
Heyo, so using this method of Character controller(Which seems awesome btw) how do we go about handling collision with object as the player has no collider?
@gunbuckybucketman4578
@gunbuckybucketman4578 2 года назад
He handle colliding with Raycast.
@mindpixel523
@mindpixel523 6 лет назад
Will you be posting a tutorial on your latest version soon! This is incredible work! Thank you for sharing with the community!
@batchprogrammer108
@batchprogrammer108 6 лет назад
Thank you very much, yes I will be uploading soon. :)
@batchprogrammer108
@batchprogrammer108 6 лет назад
I'm sorry I don't actually think I will be able to upload for a while because my computer is getting serviced but until then please download the new controller's code from the pastebin and if you have any question at all just as me and I will reply immediately and even give you code snippets if you need. :)
@mindpixel523
@mindpixel523 6 лет назад
No worries! I really appreciate it. Hope you get your computer issues resolved. Can you use a custom collider on this script for the character?i have a quadruped cat character and I don't like the sphere collider unity forces you to use. Any advice? Thanks again!!
@batchprogrammer108
@batchprogrammer108 6 лет назад
New Script just for you : pastebin.com/RdsK419R Okay I have a solution for you, so the way to use this is : Leave the sphere collider space empty. Then you put a box collider around your cat then you put that box collider inside the Box Collider option. The Box Collider is 100% needed for the collision system to work but as an extra you can also add a MESH collider into the field below, this will increase the precision of the collision, but you must have both a mesh collider and a box collider if you decide to use the Mesh collider. I would recommend to use the box collider alone and leave the mesh collider empty. If you have any questions just ask me... [EDIT : There is a small error with this script -> Replace the line - Collider myCollider; -> Collider myCollider = new Collider ();
@mindpixel523
@mindpixel523 6 лет назад
Wow! Thank you so much! I really appreciate your time on that. I'll try testing this tonight!
@purpl3grape
@purpl3grape 5 лет назад
Very nice!
@batchprogrammer108
@batchprogrammer108 5 лет назад
Thank you :)
@potnoodles9091
@potnoodles9091 5 лет назад
Hey! I know its an old video but can im really impressed with how much you know at your age, where did you learn the things in this video? Any links or books.
@batchprogrammer108
@batchprogrammer108 5 лет назад
Thank you very much! I learnt most of these things by just going through forums and stackoverflow posts haha :)
@eddied.3426
@eddied.3426 4 года назад
Thanks for this tutorial. I am going to atempt this once I am back home tonight. The main problem I had with the built in controller is my unique requirement: In the game I am building the world and everything in it including the player will be able to rotate in any direction. I need to fix the gravity so the player doesn't slide off to oblivion. The gravity must point to a "down" Vector3 rather than -y. Any ideas how to implement this?
@ignitiondj4025
@ignitiondj4025 4 года назад
Code your own gravity code and replace the default gravity used by rigidbody by a custom vector3 that points where you want.
@gunbuckybucketman4578
@gunbuckybucketman4578 2 года назад
It's sad that even in school, they only teach how to use Rigidbodies and pre-made assets. Also, your character walk up slopes because of the Gravity function keep pushing character up, not by ray check angle like other tutorial right?
@saadblabla
@saadblabla 2 года назад
What about the stairs ?
@Sinan97082
@Sinan97082 2 месяца назад
Hi, I saw your post in reddit about an reliable input recorder (unity) and that you were about to create a tutorial. Sadly I didn´t see one on your channel. Do you consider to do one, it really would help me with my final exam :)))
@11monkeyking
@11monkeyking 6 лет назад
Feeling silly, but did you just copy values from one scene to the other at about 11:00?? That alone increases my Dev production +5! Thanks (:
@batchprogrammer108
@batchprogrammer108 6 лет назад
Chris Hodges Yes I did :)
@batchprogrammer108
@batchprogrammer108 6 лет назад
I really like your double jump idea by the way, I've actually gotten a lot of suggestions but I am a bit busy with another project right now but I am keeping a list and very soon I will continue this series and it will be much better due to the support I am receiving from people like you :)
@RixiRooTM
@RixiRooTM 5 лет назад
Nice tutorial... A few problems though. I can get it to sneak through walls occasionally, and the jump height and acceleration seems to be inconsistent from jump to jump. Anyone noticed this? Any ideas? :)
@RixiRooTM
@RixiRooTM 5 лет назад
I would love to see this in a very polished state!
@thecsharpdude2190
@thecsharpdude2190 4 года назад
And how can I do this FP? So when I turn my mouse the camera rotates + It follows the player all the time????
@galerez4194
@galerez4194 3 года назад
same here
@ragewar1904
@ragewar1904 2 года назад
does anyone know a good UCC programmer ?
@rumealsmith1220
@rumealsmith1220 6 лет назад
Hi AJTech, first of all thanks for the tutorial, you really seem to know your stuff. I am having trouble with the phrases, "wallCheckDetails" and "collisionSlopeCheck". It keeps expressing these errors: " 'CustomController.wallCheckDetails(Vector3)': not all code paths return a value" and " 'CustomController.collisionSlopeCheck(Vector3)': not all code paths return a value " respectively. I have checked and re-check your code and can't determine where I might have gone wrong. Any help would be much appreciated. Here is the whole code I have written as of 28.30 minutes into the tutorial: ------------------------------------------------------------------------------------------------------------------------ using System.Collections; using System.Collections.Generic; using UnityEngine; public class CustomController : MonoBehaviour { #region Variables [Header("Speed")] public float moveSpeed; public float axisSpeed; public float rotationSpeed; public float strafeSpeed; [Header("Physics")] public float gravity; public float jumpForce; [Header("Surface Control")] public Vector3 sensorLocal; public float surfaceSlideSpeed; public float slopeClimbSpeed; public float slopeDecendSpeed; [Header("External")] public Camera playerCamera; public LayerMask discludePlayer; private bool grounded; private float curGrav; #endregion private void Update() { //Gravity(); //MouseLook(); //Jump(); //SlideMove(); //FinalMovement(); } private Vector3 moveVector; private void SimpleMove() { moveVector = collisionSlopeCheck(new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"))) * axisSpeed; } private Vector3 collisionSlopeCheck(Vector3 dir) { Vector3 d = transform.TransformDirection(dir); Vector3 l = transform.TransformPoint(sensorLocal); Ray ray = new Ray(l, d); RaycastHit hit; if (Physics.Raycast (ray, out hit, 2, discludePlayer)) { if (hit.distance
@batchprogrammer108
@batchprogrammer108 6 лет назад
Hey Rumeal, glad you enjoyed! The solution is quite easy, whenever you have a method that returns something you always have to have a return value. So at the end of the collisionSlopeCheck function just write 'return dir;' and at the very bottom of the wallCheckDetails method write 'return hit;' and I learned this from the video so you might have just missed it :) , if you want an even better player controller check out this new video it has more reliable collisions and awesome stuff like that - > ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-ona6VvuWLkI.html
@rumealsmith1220
@rumealsmith1220 6 лет назад
YES!... I AM THE MASTER OF THE UNIVERSE!!... with AJTechs tutelage of course, lol. Thanks heaps mate, it all works fine now, your a legend. I'll definitely move on to the next player controller vid once iv'e completed this one. Really appreciate the help. ;)
@batchprogrammer108
@batchprogrammer108 6 лет назад
Rumeal Smith Hahahahah glad you're enjoying my videos! If you need anymore help don't hesitate to ask :)
@theeternal6890
@theeternal6890 3 года назад
Ur voice changed drastically
@batchprogrammer108
@batchprogrammer108 3 года назад
Haha and thank god for that
@monoblanco8290
@monoblanco8290 6 лет назад
Could you add a way for us to copy the code because the controller looks really good but unfortunately I don't have the time to sit down for an hour to do this
@batchprogrammer108
@batchprogrammer108 6 лет назад
Hey, this is the old version of my character controller I have made a more stable and powerful one which I am going to make a video for. It should be up very soon! I will leave a link to the code in the description of that video! :)
@monoblanco8290
@monoblanco8290 6 лет назад
Thank you so much it will help me a lot for a game I want to make!
@batchprogrammer108
@batchprogrammer108 6 лет назад
Hey, I will give you the link to the new and updated script but I cannot make a video on it right now. I have commented all the public variables to explain what they are and how they affect the character. If you have any questions please ask me, if you could also subscribe that would be great :) - pastebin.com/8MTDuNwr
@monoblanco8290
@monoblanco8290 6 лет назад
Thank you so much
@batchprogrammer108
@batchprogrammer108 6 лет назад
You are very welcome :)
Далее
Jump And Gravity - Game Mechanics - Unity 3D
8:35
Просмотров 165 тыс.
ПОДВОДНЫЙ ГЕЙМИНГ #shorts
00:22
Просмотров 1 млн
Can we dooby Tesco's GU10 bulbs?  - with schematic
10:41
REALISTIC Foot Placement Using IK in Unity
30:09
Просмотров 126 тыс.
Linux Mint 22 Review! THE KING OF LTS?
22:16
How To Build An Event System in Unity
8:01
Просмотров 408 тыс.
Optimizing our Realtime Fluid Simulation in Unity
11:27