How to do a BACKSTAB Mechanic! (Learn Vector3.Dot, Elden Ring, Dark Souls | Unity Tutorial)
Вставка
- Опубліковано 20 сер 2024
- 🎮 Get AWESOME Synty Assets 50-70% OFF! cmonkey.co/syn...
🔴 Souls-like Essential Animations assetstore.uni...
👇 Click on Show More
🌍 Get my Complete Courses! ✅ unitycodemonke...
👍 Learn to make awesome games step-by-step from start to finish.
🎮 Get my Steam Games unitycodemonke...
🔴 RELATED VIDEOS 🔴
Kickstart your game with First and Third Person Controllers! (FREE Unity Starter Assets) • Kickstart your game wi...
SMOOTH with LERP! (Move, Rotate, Float) • SMOOTH with LERP! (Mov...
Game Dev REACTS to Elden Ring! • Game Dev REACTS to Eld...
Melee Combat System in Unity 2D (With Targeting!) • Melee Combat System in...
3 Ways to Find Targets in Unity! (Collider, Physics, Distance) • 3 Ways to Find Targets...
💬 A while ago I made a poll asking for any Elden Ring related mechanics that I could remake.
I played the game and a great mechanic that is relatively easy to do is a Backstab.
This involves using the Vector3 Dot product, you can use it to identify if behind an enemy.
And it also involves matching a Attacker animation with a Victim animation, matching the position, rotation to make the BACKSTAB really impactful!
📝 Some Links are Affiliate links which means it costs the same to you and I get a nice commission.
🌍 Get Code Monkey on Steam!
👍 Interactive Tutorials, Complete Games and More!
✅ store.steampow...
If you have any questions post them in the comments and I'll do my best to answer them.
🔔 Subscribe for more Unity Tutorials / @codemonkeyunity
See you next time!
📍 Support on Patreon / unitycodemonkey
🎮 Grab the Game Bundle at unitycodemonke...
📝 Get the Code Monkey Utilities at unitycodemonke...
#unitytutorial #unity3d #gamedev
--------------------------------------------------------------------
Hello and Welcome!
I'm your Code Monkey and here you will learn everything about Game Development in Unity using C#.
I've been developing games for several years with 8 published games on Steam and now I'm sharing my knowledge to help you on your own game development journey.
I do Unity Tutorials on just about every topic, Unity Tutorials for Beginners and Unity Tutorials for Advanced users.
You can see my games at www.endlessloopstudios.com
--------------------------------------------------------------------
- Other great Unity channels:
Unity - / unity3d
Brackeys - / brackeys
Dani - / @danidev
Jabrils - / @jabrils
BlackthornProd - / @blackthornprod
Sykoo - / sykootv
Jason Weimann - / @unity3dcollege
Jonas Tyroller - / @jonastyroller
--------------------------------------------------------------------
- Website: unitycodemonke...
- Twitter: / unitycodemonkey
- Steam: store.steampow...
🎮 Get AWESOME Synty Assets 50-70% OFF! syntystore.com/o/codemonkey
🔴 Souls-like Essential Animations assetstore.unity.com/packages/3d/animations/souls-like-essential-animations-178889?aid=1101l96nj&pubref=eldenRingBackstab
🌍 Get my Complete Courses! ✅ unitycodemonkey.com/courses
🔴 RELATED VIDEOS 🔴
Kickstart your game with First and Third Person Controllers! (FREE Unity Starter Assets) ua-cam.com/video/jXz5b_9z0Bc/v-deo.html
SMOOTH with LERP! (Move, Rotate, Float) ua-cam.com/users/shortsjAN2IoWdPzM
Game Dev REACTS to Elden Ring! ua-cam.com/video/-xqroyuoi7g/v-deo.html
@Trevorpool Yes the video is a very simple demo just demonstrating backstab logic and nothing else, there's no health system on the enemy, no find target logic, not hit detection logic, etc
Ohhhh boy!! I'm making a game that should have stealth in it and i was making a lot of tests and i finally got a way to sync the animations together!! And now you just dropped this video and the same things you did to the backstab can be applied to stealth but with some edits. And now i can combine my way and your way and make the perfect stealth system!! Thank you for this great video dude :D
That's awesome! Best of luck with your game!
it's amazing man woww
best ever moment for unity developers when actually codemonkey started game dev in 3D :D
Hoping to see a 3d game from you on steam someday.
Hoping to see you soon on Jason Weimenn live shows... Last week or 2 weeks before, he said it will be great if CodeMonkey can join.
A parry mechanic would be really nice to see. Great video as always!!
As a small nitpick which doesnt really change the video itself:
If you are behind someone and attack it triggers a "Attempt backstab" animation (ocourse only if the target is backstab-able). If the hitbox of the weapon hits the target, doesnt matter where as long as the target gets hit by the "Attempt backstab animation"(which only triggers if you are behind someone), only then the backstab animation like in your video plays.
If its PvP, then the "Attempt backstab" animation also needs to hit the enemy's back, otherwise it wont suceed.
There is a great video about it called "Why Elden Ring changed backstabs - A history of the Soulsborne backstab"
Very interesting video! Thanks for the link!
Since you covered this, You should do a tutorial on melee combat and melee executions with the starter assets!
this ive been waiting on that for a long time
This one was pretty easy. Would love to see no loading screens mechanics. Like Bloodborne for example. You can progress through the whole game without ever seeing loading screen.
That's something that I would really like to see
just async load multiple scenes, all you need is to have a trigger collider in different zones to load/unload scenes that are close/far enough
@@zerogamedev I know how this works mate. Just want to see our friend's code monkey approach on this. In the end there is more than one way to skin a 🐒.
I remember the reason why I started making my own game. If you can't buy the game, make the game. If there's no game that you like, do it yourself.
This kinda feels like it, if you can't play Elden Ring, then do it yourself where you can play it. I do have portable consoles but there's still a game I'd like to see but rarely everyone do today.
These are the type of tutorials I absolutely adore, where you show how to put to remake actual features from other games! Great as always Mr.CodeMonkey! :)
Ohhh sweet. I already have one in place in my project but I'm always down to see how others do it. It's always interesting to see.
This could not come at a better time, I need this for a game of mine. Thank you!
Great video,
never played Elden Ring
but I always love to learn something new in Unity.
I mostly worked in 2D only,
just getting started in 3D
and your Tutorials are amazing for that.
Also great idea to use the Synty Assets
as they have been on sale or in a bundle a lot lately.
The Fantasy Kingdom Set is currently on sale for -70%
It is really great to see u r now doing 3d tutorial for a while🙂
My main issue with 3D was always lack of assets but since I've bought so many over the past years now I have enough assets for pretty much any prototype I want to make!
Awesome tutorial ... I like that you back to this kind of videos as well. Keep it up!!
Definitely going to apply this feature to my game. ☺️ Riposte and stagger as well.
Can't wait to see you post some Dark Souls-like dev tutorials!!!
Amazing video as always. I wish we get a climbing system in the future even if it's a basic one.
There is a match frame method on an AnimationController. I used it to mach end of movement at exact position
I am making like a dark souls type game (I would not say a clone) and this helps keep up the good work!
The plunging attack !!!
Thank you so much for these! I stopped doing game dev about 10 years ago (C# and XNA, also C++ and DirectX/OpenGl) and wanted to get back into it using Unity... I hated programming HLSL. Most of my experience with Unity is making tech demos... although I got really good at integrating Unity with Twitch and building a Twitch bot in Unity (still trying to figure out UA-cam integration). I just got all of your courses a few weeks ago and I'm really looking forward to your XCOM remake course.
The one question I have is how would you handle mod support in Unity. I have a good idea on how to implement 3D/2D assets and stats... have Unity dynamically load files from a resources folder with a model and an associated text file (for stats). But how would you allow modders to upload custom scripts (that change how the core game functions) for Unity to use? Would you use something like LUA or does Unity have it's own implementation?
The other things that I'm interested in is how to program a multiplayer game (in XNA it wasn't as straight forward), how to setup and host a stats server (ie leaderboards, daily challenges), developing over multiple OS, how you do your debugging/testing, and how to publish to steam.
Once again thanks!
Yup for stats you really just do File.ReadAllText on the Application.dataPath, could be a basic .txt file or some JSON
Same thing for loading images, just load the bytes and load the Texture into Unity ua-cam.com/video/Gk0-amfn5DM/v-deo.html
For custom scripting, that's actually something I've never done and I'd love to research, LUA would indeed be a good approach, I don't think there's any built-in Unity tool.
There's also a C# Runtime Compiler that I picked up a while ago, looks interesting but haven't tried it yet assetstore.unity.com/packages/tools/integration/roslyn-c-runtime-compiler-142753?aid=1101l96nj
For multiplayer, Unity's official tech called Netcode for Game Objects is currently in preview, when it's out I'll definitely be doing some tutorials on it docs-multiplayer.unity3d.com/
Best of luck in your learning journey!
@@CodeMonkeyUnity I recall Unity themselves doing a poll about mod support while back and I think it went through, meaning we might see a official mod support in few years.
If your interested in the math behind Dot products Freya Holmér did a great video explaining it.
Yup Freya has some excellent math videos!
This video is on a whole other level!
Wow really cool dude !!! .. was this for mee ? yesss meeeee !!!
Are you implementing a backstab in your game? I hope the video helped!
wow awesome! I was thinking to just get the state of the enemy (stunned) and then do the backstab when conditions are met but this is a whole package when it comes to checking distance and positioning of the characters! Thanks mastah! ^^
No Wonder my teacher said, as a game designer, we have to be good at math XD. Thanks for your video
Great stuff!
Love it!
Great design! Also a cleaning looking game and particles.
A series for making cool mechanics from dark souls like would be cool.
I need this .. thanks
I love you man
I haven't watched video yet, but I bet there's gonna be a dot product somewhere.
2nd 🙂Very nice math tut .. i 1st time seeing math in action 😂
heh yup, math becomes much easier to understand if you see it in action
This is the next level tutorial, very cool video ...can't wait a video on how to make enemy take damage on head shot
Awesome video, always wondered how to do it
I love your Videos, and i got one of your Courses, i didn't started yet, but it looks very goog
I hope you like it! Feel free to ask any questions in the Q&A section, I answer all of those every day
Great tutorial!
Thank you so much for that!! Can you also make a video about parrying with a shield or another sword?
parry mechanics would be interesting to learn
I'm going to reiterate my request for a Snake Pass kind of movement. I;ve never seen it done by any of the gamedev YTer. Mark Brown has a video on the generalities but no one has the specifics
I need to find the time to play it first, I do remember watching that GMTK video but don't remember how the snake moves.
It think you just move it left/right/up/down which applies some rotation to the forward vector while also moving the snake forward.
@@CodeMonkeyUnity iirc, the controls are for the head to point left, right, up, or down and there's a separate control for just forward which moves only the head in the direction it's facing then pulls the rest of the body behind. I've never played it myself but I think the description in the GMTK video is enough. I did try to make a similar movement in Unity but alas could not figure it out.
you should do bloodstains from elden ring
Do you have a tutorial for target selecting? Since, in this tutorial we are hard coding in the enemy reference
I covered several methods here unitycodemonkey.com/video.php?v=h9oEhVqGptU
normal getting hit animation is playing every time while attacking even if the enemy is way far
Yup in a proper game you would add some logic for actual hit detection
after I hung a navmesh on the enemy, the script no longer works how to fix it
What are the up- and downsides of using this dot-Product method instead of using box triggers behind enemies?
This is much more simple and much more performant, adding extra game objects and extra physics colliders has a certain cost and if you add them to every single enemy then that cost can really add up
nice
great work thnx
Alright who's ready to find the spy. Right behand you.
Remember to balance it well, nobody wants chan backstabs back
Good
In a nutshell
1. Add backstab animation asset
2. if (behind) do animation
Do Inner Product to know whether behind or not
Yup it's pretty simple! The tricky part is knowing about how Vector3.Dot works
Please do an RPG 3d series 🙏🙏
Maybe one day!
very cool
How do you do this with multiple enemies? As how do you recognize which one you are attacking in order to get its position?
You could use the direction of the camera to identify which one you should target, I made a nice targeting system for a melee video a long time ago and that same logic could be used here ua-cam.com/video/AXkaqW3E9OI/v-deo.html
Or other methods for finding a target ua-cam.com/video/h9oEhVqGptU/v-deo.html
Hi Code Monkey, could you do word connect word board generation randomly ? it would be great, i tried a lot of and my code so far but still it doesnt work very well or can you give me any idea for this generation
Love from italy
Like a word puzzle where the letters connect? I'm not sure if there's a specific algorithm for that type of generation but brute force might work, pick a random word, then go through the letters and find more random words that start with those letters or have them in the middle and so on. It's not pretty but brute force should work.
@@CodeMonkeyUnity It just works between two words, i tried it with this method, its really hard man :)
Codemonkey, I got a problem and not many youtubers actually provide solutions. How do I make footstep sounds with a blendtree? Animation events don't work in this case. Awesome video about the elden ring by the way
Animation events do work but only one of the active animations will play them. I can't remember if it's the first one that starts animating or the one most active.
When I had that problem I just added Animation Events to all the animations on the blend tree
If that absolutely does not work, you can get the Foot bone position and do a raycast to see when it hits the floor
@@CodeMonkeyUnity Thanks!
Absolutely love the video!!
I have a question, sometimes my backstab doesn't position itself correctly when my enemy is chasing me. I am stopping the movement as well before doing anything as well. Any ideas why this is happening? thank you :)
Hard to tell why because chances are it's related to whatever character controller or animation system you're using. Is the position wrong or just the rotation? Does the animation have root motion? You probably have another script conflicting with the backstab script and you end up with 2 scripts moving the same object
@@CodeMonkeyUnity Got it, So it turns out when you are using a character controller you must disable it before setting it's gameObjects transform. This is due to the fact that the character controller is constantly setting the position of the gameObject. Thanks heaps!
How did you get the player to face the direction of rotation when he gets back up? When I transition back to idle it rotates my character?
Also do you have a discord?
Awesome tutorial, thank you!
Can you show us how you setup the animator and transitions, or do you have a tutorial somewhere on it? I am using the third person asset(that tutorial was great also!!)🙂I have the melee working OK, but the transitions are kind of wonky. I have watched your "New Input System" video and it was great, I didnt even realize they had a new input system! lol Thanks so much!
It's just a trigger transition to go into attack/backstab state and then automatically back into idle/walk when that state is over. I don't have a UA-cam video just on that topic but I do cover the animator and animator parameters in my ultimate unity overview course
Great video! Would it be possible to make a tutorial on infinite (or very large) pooled inventories using scroll rect? I've managed to create an inventory and such, but when it gets very large (200+ items), it causes massive performance issues (understandably). I haven't been able to get one working because I'm a complete dumbass.
What would you do, if you have multiple enemies? Now you have set the one enemy per drag and drop but if you have 3 enemies, how would you habdle it?
You would have some kind of find target logic to find which target it should attack ua-cam.com/video/h9oEhVqGptU/v-deo.html
ua-cam.com/video/AXkaqW3E9OI/v-deo.html
@@CodeMonkeyUnity thank you. This really helped
I feel that most of our videos are transitioning to 3D now is it?! and i do wonder, will this work while walking?
As long as I can find assets then 3D is great!
In a more complex example the player would have some sort of state machine that would disable moving while the backstab animation is playing
@@CodeMonkeyUnity oh id love to try this out in a sample scene like a dark souls type game
im still learning but a quick question. In a full game dev setting wouldnt it be better to give a pc or npc a defined front and back say with their character controller placed on the target. that way rather than getting the vector 3 ref you are getting the predefined based on position direction the target is facing. im still training my thoughts when im am learning programming and game dev to think about how to make the code over all modular.
You could but you would add unnecessary colliders. If the goal is exactly this, just knowing when something is in front or behind, then simple math is better than colliders.
@@CodeMonkeyUnity ahh so code is better here. Thank you. Would that also mean making a back and front with code for all npcs is better?
@@dayanson6920 This logic works with anything, doesn't matter if it's an NPC or Player or an inanimate object, it just looks at a transform forward vector. So there's no need to add colliders to all the various objects you want to have this logic
Hello ! Could you also help us to make a mêlée controller ? Like you did for the TPS tutorial ? It would really help us to fit this backstab with a Real controller 😇
Yup I definitely want to do that!
@@CodeMonkeyUnity you became literally the tutorial God about unity 🥰
I can't find thirdPersonController.setTargetRotation
It's not a built in function, I added that for this demo, it just rotates the object smoothly towards a certain target rotation. The smoothness is with Lerp unitycodemonkey.com/video.php?v=jAN2IoWdPzM
@@CodeMonkeyUnity thanks for answering , I appreciate it
How did you do the blood effect and whatnot, the impact is really cool, would love to see a vid!
It's a particle effect from the Polygon Particle pack, it just gets instantiated when the Animation Event triggers
@@CodeMonkeyUnity Aaah, I see. Would still be interesting to see how to put something like that together in a tutorial though !
Would having some sort of trigger behind the enemy work as well?
Sure, you could make the logic hitbox-based instead of math-based. Possibly combining with an attempt backstab animation, test if the sword hitbox touches the back hitbox and if so do the backstab
Wouldn't it have been better to move the player to behind the enemy?
As in if we sneak up on the enemy, why would they step back into a back stab, the player should step forward instead
Usually the player has more complex logic than the enemy, so moving hte enemy could be simpler
@@CodeMonkeyUnity kinda lazy, and it doesn't look good
@@SaadTheGlad Whichever one you move will look the same. In order to make the animations match one of them must move.
hi~awesome tutorial!how can i get the source code?
I didn't make a package for this one since in terms of code everything is simple, all the backstab code is shown in the video
@@CodeMonkeyUnity no you didnot what about the function of rotatetofacecameraforward function in playerbackstab script
You associate backstab with Elden Ring, i associate backstab with spy from TF2, we are not the same
Please link to source code
I didn't make a package for this one because all the code is shown in the video so there's no need. It's really just the Vector3.Dot and Vector3.Distance
Well better make to move player not enemy with animation, bc it looks just bad! That sliding.
Either way one of them will be sliding, you could increase the speed to disguise it or limit the max backstab distance
Which application is this
This is Unity ua-cam.com/video/E6A4WvsDeLE/v-deo.html
First
Eh, you kinda gloss over the details that go into the how the code works
How so? All the backstab code is written in the video.
What part would you like to know more about? The character controller? It's from the Unity Starter Assets ua-cam.com/video/jXz5b_9z0Bc/v-deo.html
@@CodeMonkeyUnity mostly the fact that player has a reference to the enemy
Not realistic
@@juicedup14 I covered find target logic here ua-cam.com/video/h9oEhVqGptU/v-deo.html
4th
spt tf2
eww...elden ring there only for hype. er uses same parry/backstab as des and ds 1,2,3
duh? its the same game from 10 years ago
Good
Good