[Unity C#] First Person Controller (E03: Fixing Slope Bouncing and Jittering)

  Рет қаралды 64,354

Acacia Developer

Acacia Developer

Күн бұрын

Пікірлер: 130
@fishbox385
@fishbox385 3 жыл бұрын
This comment is like 3 years later but thank goodness i found this channel, you're amazing dude.
@troy9217
@troy9217 5 жыл бұрын
This is the series of videos I've always needed! Thanks so much Matthew!
@scoobynicker
@scoobynicker 3 жыл бұрын
Thank you! Been I've been putting off fixing this exact issue in my game for months. I wish I would have found you earlier.
@user-og6hl6lv7p
@user-og6hl6lv7p 5 жыл бұрын
Instead you could align a seperate gameobject to the collision surface normal and then use then use that gameobject as a directional reference for your character movement. So if you're on a slope the direction reference gameobject will rotate to match the surface normal, then you move your character while referencing the aligned gameobject, so it would look something like this: fowardMovement = directionReference.forward * vertInput; rightMovement = directionReference.right * horizInput; This way you don't have to constantly apply a ludicrous amount of force to the character saving a bit of overhead.
@rodolf5941
@rodolf5941 4 жыл бұрын
THANK YOU!!! This problem gave me brain damage. I tired everything, I mean, everything. Including increasing the gravity. But I never thought about increasing the gravity ONLY when you're on stairs or similar objects. Thank you man, even 2 years later, you're still extremly helpful
@crazecrazie
@crazecrazie 6 жыл бұрын
PSA, if you remove 'if (hit.normal != Vector3.up)', it will fix the jittering on stairs too (with the jump bool keeping the whole thing from breaking after removing that code). Adjusting the slope limit while not jumping will still give you some play room with terrain slopes, i recommend serializing this value.
@DoomVisuals
@DoomVisuals Жыл бұрын
Or instead, have smooth stairs, add an invisible ramp on the stairs, it's smoother.
@NathanTheCraziest
@NathanTheCraziest 2 жыл бұрын
Thank you so much for the proper explanation in a way i could understand, many other tutorials were too hard to understand but yours was very well explained, you deserve more subs
@gr8m8n8
@gr8m8n8 6 жыл бұрын
I cant believe this worked for me! THANK YOU I looked everywhere and no one actually has a solution as effective as yours!
@Xyz-q9f
@Xyz-q9f 3 жыл бұрын
Incredible tutorial, worked 1000x better than any other I worked through
@dynamicvoltage9765
@dynamicvoltage9765 8 ай бұрын
If you're already shooting a ray down, you might as well just set the player to the ground by measuring the distance to the floor. By adding extra gravity you run the risk of changing the speed at which the player moves.
@simpleguyissimple
@simpleguyissimple 4 жыл бұрын
your channel is so underrated. greetings from the Philippines ! you're the best man.
@nostalgia7211
@nostalgia7211 2 ай бұрын
Thanks, buddy! Thanks to you, I managed to solve the problem of sliding for surfing.
@PhantomWolf93
@PhantomWolf93 3 жыл бұрын
I had this problem for a long time and your video has been of great help, both to understand the problem and to solve it. Thanks so much :)
@javac9158
@javac9158 5 жыл бұрын
Better yet, you can "rotate" your move input to follow the curvature of the terrain. Simply find the normal of the ground and do ``` Quaternion rotation = Quaternion.FromToRotation(transform.up, groundNormal); move = rotation) * velocity; ``` and then use the move variable to control the player. This way you don't have to add an additional force when moving on slopes
@Mr.Epsilion
@Mr.Epsilion 5 жыл бұрын
good solution :) thanks Lane
@creasu124
@creasu124 4 жыл бұрын
This is a very nice solution I think this is a very nice way of doing it
@melowfx
@melowfx 3 жыл бұрын
Hello! I really don't understand how to implement this system into my player controller, could you help me please? I'm struggling with problem so long ( how can I share pastebin, my comment gets deleted)
@SonictheHedgehogInRealLife
@SonictheHedgehogInRealLife 2 жыл бұрын
Like this? Quaternion rotation = Quaternion.FromToRotation(transform.up, hit.normal); moveDirection = rotation * (Vector3.ClampMagnitude(forwardMovement + rightMovement, 1.0f) * movementSpeed);
@SonictheHedgehogInRealLife
@SonictheHedgehogInRealLife 2 жыл бұрын
it didnt work
@tapoutluke
@tapoutluke 4 жыл бұрын
exactly what i was looking for. Thank you!!!
@OxisTech
@OxisTech 3 жыл бұрын
this tutorial is a good easy fix unless you need to jump while on the slope
@dagmarski4133
@dagmarski4133 3 жыл бұрын
You could code it so it behaves normal when jump is pressed
@null987
@null987 6 жыл бұрын
Does the normal return a vector perpendicular to the surface? Very good tutorial, easy to understand and concise! Keep up the good content!
@AcaciaDeveloper
@AcaciaDeveloper 6 жыл бұрын
Yes, that is correct. The normal vector points away (perpendicular) from the surface that a ray hits. Glad to hear you enjoyed!
@Rosstail
@Rosstail 3 жыл бұрын
Thank you, some tutorials explained this for 2D, and the documentation gave another name for the 3D one ^^. After some Vector cross it is really possible to make a character slide on a high pitch ^^
@SonictheHedgehogInRealLife
@SonictheHedgehogInRealLife 3 жыл бұрын
I'm trying to make the character move on ramps loops walls ceilings any angled slope I have the player rotating by getting the surface normal from a raycast. I can move on flat ground but the player stops when trying to run up the ramps and onto walls
@forcepower7116
@forcepower7116 6 жыл бұрын
Please do Crouching next Love this Series so far
@AcaciaDeveloper
@AcaciaDeveloper 6 жыл бұрын
Glad to hear it. Crouching and sprinting are planned for the next two episodes.
@WeegeepieYT
@WeegeepieYT 6 жыл бұрын
yay :D
@scotttrexler9947
@scotttrexler9947 6 жыл бұрын
Saves me from having to ask. Can't wait for these videos... and thank you for the ones you've already done!
@mdthevideogame
@mdthevideogame 4 жыл бұрын
Acacia Developer hello Matthew
@zenrepublic97
@zenrepublic97 3 жыл бұрын
Saved my life, way too good of a tutorial
@iDerp69
@iDerp69 5 жыл бұрын
Incredibly useful video, wow. Thank you!
@RetroAnt3
@RetroAnt3 4 жыл бұрын
Thank you so much. This ruined my game and you helped me fix it. You deserve much much more Views and Subs
@chikaychhann5628
@chikaychhann5628 5 жыл бұрын
Keep it on, I always watch your videos
@AthosSampaio
@AthosSampaio 4 жыл бұрын
Thanks for the tutorial. Clear and very useful!
@unhommequicourt
@unhommequicourt 4 жыл бұрын
well i m still bouncing. I just can t jump from slopes anymore with this code
@headrushgaming2614
@headrushgaming2614 4 жыл бұрын
wouldn't this make jumping on a slope impossible if your'e using rb.AddForce or animation controllers and a capsule collider
@bekirkagankaraahmetoglu
@bekirkagankaraahmetoglu 4 жыл бұрын
It looks like we can use it for climbing on a vertical wall am I right?
@RichardGardnerUK
@RichardGardnerUK 3 жыл бұрын
Why not just apply the force in the direction of the input and slope? It seems like changing gravity is just going to open up a can of worms in the long run. I found the reason for the skipping was because you are trying to apply a directly horizontal force when you are not on a completely flat surface. The same can be said when going up slopes, without the force applied in a relative direction you will find yourself slowing down as you essentially run into the ground.
@SonictheHedgehogInRealLife
@SonictheHedgehogInRealLife 2 жыл бұрын
howwww
@virtuagames4957
@virtuagames4957 5 жыл бұрын
Great Tutorial, Thanks a lot, it helped me right now
@samhsmith
@samhsmith 6 жыл бұрын
My solution for this is to rotate the move force so that it is perpendicular to the surface normal
@justinc2633
@justinc2633 5 жыл бұрын
parallel?
@SonictheHedgehogInRealLife
@SonictheHedgehogInRealLife 2 жыл бұрын
Howwww
@johni3080
@johni3080 4 жыл бұрын
Amazing tutorial, but one fix, I think you want to add the slopeForceRayLength to charController.height / 2 and not multiply in Physics.Raycast if statement, line 58
@IT-vy7kx
@IT-vy7kx 5 жыл бұрын
Thank you! Get this guy out there!
@kovacsbence5521
@kovacsbence5521 4 жыл бұрын
For some reason, moving up platforms makes the code think you are actually not moving? Yeah okay, seems like the problem was with some Animation script. Thank you very much for your help nonetheless!
@CAESAR_IS_GOD_mohammadisaloser
@CAESAR_IS_GOD_mohammadisaloser 3 жыл бұрын
This works until I perform a jump and then it goes back to bouncing? heres my jump code its different than yours if (controller.isGrounded) { moveDirection.y = 0f; if (input.GetButtonDown("Jump")) { isJumping = true; moveDirection.y = jumpForce; audioSource.PlayOneShot(Jump, 0.5f); } } is it just a placement issue possibly ? do I have to have it in a particular order?
@CAESAR_IS_GOD_mohammadisaloser
@CAESAR_IS_GOD_mohammadisaloser 3 жыл бұрын
forget it figured it out had to add an else { isJumping = false; } line after my jump code.
@mrworld8494
@mrworld8494 3 жыл бұрын
sooo good i really needed this!!
@94call
@94call 4 жыл бұрын
Thank you so much!! You saved me a lot of time
@SDFTDusername
@SDFTDusername 5 жыл бұрын
can you please teach us that if we are on the slope the camera will face to the slope direction
@maevixie7041
@maevixie7041 3 жыл бұрын
When my character is trying to go up a slope, it gets heavily slown down. Going down is fine. I'm using a rigidbody instead of character controller but I think I've managed to edit the code shown in the vid to be suitable for rbs. Any idea what might cause this to happen?
@pandarzzz
@pandarzzz 6 жыл бұрын
Thank you for sharing this informative video!
@yester8946
@yester8946 3 жыл бұрын
Great video but there's a problem: if I set the slope force to a high number to remove the small bounces, I can't jump when going up until I stop which then would process the jump mechanic. NOTE: I use Brackeys FPS movement tutorial
@LowResDev
@LowResDev 5 жыл бұрын
This particular method doesnt seem to allow for mid air movement. How could I implement this?
@user-og6hl6lv7p
@user-og6hl6lv7p 5 жыл бұрын
Have you tried increasing movement forces while the character isn't grounded?
@NeZ3RR
@NeZ3RR 4 жыл бұрын
Hi i have a problem with if ((vertical != 0 || horizontal != 0) && onSlope) it shows error Operator '&&' cannot be applied to operands of type 'bool' and 'method group'
@NeZ3RR
@NeZ3RR 4 жыл бұрын
oops my bad the && onSlope should have ()
@Berniebud
@Berniebud 3 жыл бұрын
im having the issue where my character is constantly sliding down even the slightest slope
@jsj0520
@jsj0520 4 жыл бұрын
i of course was working on my own project and didnt have the same code as you but when i went to go test if i have the slope force at 0 my character moves down normal, but if i have it at any number above 0 he starts to bounce down again. idk whats going on but im not complaining XD.
@5_Fallen-3f
@5_Fallen-3f 4 жыл бұрын
Thank you so much. Amazing video.
@AevenIridescent
@AevenIridescent 6 жыл бұрын
What i did when dealing with this issue was projecting the horizontal movement into the normal plane of the collider im hitting, simply done with Vector3.Project, as long as a very small raycast hits, so im not floating midair
@SonictheHedgehogInRealLife
@SonictheHedgehogInRealLife 2 жыл бұрын
yooooo i cant get it to work ive tried doing the same thing
@AevenIridescent
@AevenIridescent 2 жыл бұрын
@@SonictheHedgehogInRealLife make a downwards raycast bellow your character, get the normal out of the hit, then use Vector3.ProjectOnPlane using the direction you wanna go and the normal you got.
@SonictheHedgehogInRealLife
@SonictheHedgehogInRealLife 2 жыл бұрын
@@AevenIridescent I did do this but for some reason it's only working on flat planes. I have a ramp that's smooth like a sonic game and when the rigidbody goes down the ramp it jitters.
@AevenIridescent
@AevenIridescent 2 жыл бұрын
@@SonictheHedgehogInRealLife you might be messing up which vectors you're using, try using gizmo.draw to debug the vectors. But if you're making a sonic like game, then the problem could be another one, if the ramp is too steep the raycast could be failing to hit
@SonictheHedgehogInRealLife
@SonictheHedgehogInRealLife 2 жыл бұрын
@@AevenIridescent could be a possibility My ray cast seems to be working it gets the surface Normal of the ramp successfully. I'm casting the raycast down from the player. The player can rotate successful with the surface Normal. I'm not sure what could be going wrong. Can I see your code if you have it?
@animadoarts5123
@animadoarts5123 5 жыл бұрын
Will it also climb the hill.. without resistive force
@louislemur
@louislemur 3 жыл бұрын
OMFG EXACTLY WHAT IM LOOKING FOR
@AgressivePigeon
@AgressivePigeon Ай бұрын
You are a godsend.
@m.h.kstudio1740
@m.h.kstudio1740 3 жыл бұрын
this tutorial is a good easy fix unless you need to jump while on the slope how to jump in slope ???\
@노성엽-y2k
@노성엽-y2k 3 жыл бұрын
Can you even climb trees?
@beandevelopment9503
@beandevelopment9503 4 жыл бұрын
where did u go I love these vids there ultra helpfull
@aberrantcurse8551
@aberrantcurse8551 5 жыл бұрын
how do you detect which way the slope is facing?
@aberrantcurse8551
@aberrantcurse8551 5 жыл бұрын
nvm i got it
@xdplai3190
@xdplai3190 4 жыл бұрын
Can anybody help me i have tried this but its not working. I found out the mistake by printing hit.normal which is always giving (0, 0, 0) even when i am on slope
@dylanfoster186
@dylanfoster186 4 жыл бұрын
your raycast isnt hiting a collider. Make sure the raycast length is long enough to reach the ground.
@connorc1742
@connorc1742 5 жыл бұрын
How do i prevent the slope force from weighing down my jump height when walking???
@connorc1742
@connorc1742 5 жыл бұрын
And this won’t make my jump height less when walking?
@CornRecords972
@CornRecords972 5 жыл бұрын
@@connorc1742 Lemme explain it's because the additional gravity for slopes is only applied when the person is on a slope and not jumping so as soon as the player jumps the extra gravity is removed
@connorc1742
@connorc1742 5 жыл бұрын
@@CornRecords972 Wait can you message your full script? im kind of confused on where to put this
@CornRecords972
@CornRecords972 5 жыл бұрын
@@connorc1742 Rewatch the tutorial and look for where he put the code then compare what he types to mine. If I show you everything you wont learn.
@chaos4living676
@chaos4living676 4 жыл бұрын
Doesn't work for me, it say that there is no definition for height and that is not accessible extension method 'height' accepting a first argument of type 'PlayerController' I'v read your code and don't understand how you can do but .height seem to be shitted out of nowhere as far I am concerned. Tumb down
@unhommequicourt
@unhommequicourt 4 жыл бұрын
i think you just misspelled height. i don t have compilation error
@iR3dy
@iR3dy 3 жыл бұрын
will this work for third person
@durr4n371
@durr4n371 5 жыл бұрын
it says for me: Invalid expression term '&&' any help?
@TheGordonFryman
@TheGordonFryman 5 жыл бұрын
Hey! Are you still getting this error? If so, can you show me your script?
@durr4n371
@durr4n371 5 жыл бұрын
@@TheGordonFryman hi, I was getting the error but I've since changed interests in game design and have uninstalled unity
@justinc2633
@justinc2633 5 жыл бұрын
@@durr4n371 hahaha
@dcat1832
@dcat1832 Жыл бұрын
how to jump?
@alextang5268
@alextang5268 6 жыл бұрын
please make a vid on how to get the player to be able to move while in mid air
@pixelfiltergames2310
@pixelfiltergames2310 6 жыл бұрын
alex tang why that is not even a thing that needs any code to not make him move in mid air is harder
@fd8373
@fd8373 4 жыл бұрын
A year ago this work for me but now it do´nt . Any ideas ?
@unhommequicourt
@unhommequicourt 4 жыл бұрын
i don t know i tried this today and the code does nothing i m still bouncing.
@u.s7072
@u.s7072 6 жыл бұрын
great series, looking foward the sprint / crouching
@pixelfiltergames2310
@pixelfiltergames2310 6 жыл бұрын
† † † U.S come on for sprinting increase speed and change animation crouch decrease speed change animation
@322ss
@322ss 6 жыл бұрын
Thanks for the videos! Interesting approach for grounding player in slopes, but would this work for capsule collider with physics movement as the floor could be slippery? Also, couldn't you just add the downward force whenever not jumping? Another idea - if you really want to glue the player to the ground, have you tried alternatively to just move the character downward based on raycast hit?
@AcaciaDeveloper
@AcaciaDeveloper 6 жыл бұрын
Hi, good questions. "but would this work for capsule collider with physics movement as the floor could be slippery?" I'm unsure about how rigidbody physics would react exactly since I've built this tutorial for a character controller (that doesn't interact with Unity's physics system). If you're adding custom physics materials to your ramps and trying to pin rigidbody objects down onto it, then that could be something good for you to test out to see what does and doesn't work. "Also, couldn't you just add the downward force whenever not jumping?" Yes, you can do that, but it could introduce unwanted side-effects depending on how the controller is being used. I'd prefer to implement some extra computation to make sure that I'm only applying additional downward force when it's needed. It's also the case that if the player simply walks off a ledge, they will fall to the ground very fast since the space bar was never pressed to trigger the jump. You'll probably have to do an additional check to the isGrounded boolean on your character controller to solve this issue, although from my experimentation, this caused some other problems. "if you really want to glue the player to the ground, have you tried alternatively to just move the character downward based on raycast hit?" I've tried setting the player controller's position directly to n number of units higher on the y axis than the hit point on the floor. This caused jittering as the player walked onto and off the ramp, and the movement on the ramp seemed slightly more sharp and sudden than it should be.
@joshuamason2227
@joshuamason2227 5 жыл бұрын
what happens when you jump on a slope while walking though?
@lilcatfriend4575
@lilcatfriend4575 5 жыл бұрын
the whole thing poops out IVE BEEN TRYING TO FIX IT BUT CAN'T THINK OF HOW TO DO IT
@joshuamason2227
@joshuamason2227 5 жыл бұрын
@@lilcatfriend4575 I think to fix it you need to abandon the whole add gravity thing and try some new methods. Just a suggestion, I ain't no expert
@illusen1020
@illusen1020 5 жыл бұрын
I just threw the "if (verticalInput != 0 || horizontalInput != 0 && OnSlope())...." into another "if (!isJumping)" because if I'm jumping I don't care if there's a slope beneath me or not
@damgaronfire
@damgaronfire 5 жыл бұрын
5:00 the heck are those signes
@ksew9269
@ksew9269 5 жыл бұрын
OR operator
@WhereisYunoGasai
@WhereisYunoGasai 5 жыл бұрын
damgar Video Jeux signs*
@technoo4891
@technoo4891 3 жыл бұрын
learn c# first before trying to learn unity, fucks sake..
@damgaronfire
@damgaronfire 3 жыл бұрын
@@technoo4891 dude that was 1 yr ago y you booly me
@goncharov000
@goncharov000 6 жыл бұрын
awesome stuff
@Dudi4PoLFr
@Dudi4PoLFr 6 жыл бұрын
Could you do a episode about Crouching, Sprinting/Walking?
@AcaciaDeveloper
@AcaciaDeveloper 6 жыл бұрын
Crouching and sprinting are planned for the next two episodes.
@Dudi4PoLFr
@Dudi4PoLFr 6 жыл бұрын
@@AcaciaDeveloper Great news! Thank you for your replay.
@i3m1r
@i3m1r 6 жыл бұрын
please make running, incline and creep
@mdthevideogame
@mdthevideogame 4 жыл бұрын
Hello Matthew
@shalluxi7184
@shalluxi7184 5 жыл бұрын
Thank you!
@joegrizzly999
@joegrizzly999 5 жыл бұрын
Or you can us a invisible collider for a smooth slope game do that for a easy fix
@yekclateuputhomas3452
@yekclateuputhomas3452 4 жыл бұрын
very cool ty
@yassineaguedid1929
@yassineaguedid1929 4 жыл бұрын
i love acacia trees :D
@giovannicunha2529
@giovannicunha2529 6 жыл бұрын
Nice
@AmgedAlfakih
@AmgedAlfakih 4 жыл бұрын
this didn't work with me
@alicewithalex
@alicewithalex 6 жыл бұрын
Very cool
@danlmult
@danlmult 4 жыл бұрын
Thanks!
@leandroleveron9933
@leandroleveron9933 4 жыл бұрын
Thank you sir.
[Unity C#] First Person Controller (E04: Running and Walking)
5:49
Acacia Developer
Рет қаралды 19 М.
Why Stairs Suck in Games... and why they don't have to
11:24
Nick Maltbie
Рет қаралды 1,5 МЛН
Ozoda - Alamlar (Official Video 2023)
6:22
Ozoda Official
Рет қаралды 10 МЛН
요즘유행 찍는법
0:34
오마이비키 OMV
Рет қаралды 12 МЛН
УЛИЧНЫЕ МУЗЫКАНТЫ В СОЧИ 🤘🏻
0:33
РОК ЗАВОД
Рет қаралды 7 МЛН
JISOO - ‘꽃(FLOWER)’ M/V
3:05
BLACKPINK
Рет қаралды 137 МЛН
[Unity] First Person Controller [E01: Basic Controller]
20:51
Acacia Developer
Рет қаралды 161 М.
He said I Couldn't Make a 3D Game... So I Made One!
10:29
Dani
Рет қаралды 9 МЛН
[Unity C#] First Person Controller (E01: Basic FPS Controller and Jumping)
24:14
7 Outside The Box Puzzles
12:16
MindYourDecisions
Рет қаралды 28 М.
Unity 3D - Rigidbody VS CharacterController [UnityQuickTips]
18:56
Master Indie
Рет қаралды 160 М.
Unity3D Character System On Slopes!
23:03
Renaissance Coders
Рет қаралды 55 М.
How to make The Best First Person Camera in Unity
9:04
semikoder
Рет қаралды 27 М.
Ozoda - Alamlar (Official Video 2023)
6:22
Ozoda Official
Рет қаралды 10 МЛН