You are a godsend man. I'm up here for at 1am trying to figure this out for hours for a class demonstration the next morning and I can't thank you enough. Finally works!
This also works in 2D! I tried this tutorial and at first I struggled a lot because nothing happened and I didn't know what I had done wrong. Then I realized if you are using 2D Colliders etc. you need to change one line of code to make it work: private void OnTriggerEnter2D(Collider2D other)
Hi, thanks for the tutorial. I have a problem with the MyAnimationController variable, though. I am using an array of prefabs as collision triggers, if I set the component that MyAnimationController asks through the inspector (as seen at 8:20) on those prefabs (I am assigning it "Avatar", as my Avatar is my player and it's the GameObject on which I want to change the animation on trigger collider with the prefabs), even if I hit "apply all" in the inspector, after I delete the prefabs from the hierarchy (as I only leave their spawner) and I start the game I get this error: " UnassignedReferenceException: The variable MyAnimationController of playMyAnimation has not been assigned. You probably need to assign the MyAnimationController variable of the playMyAnimation script in the inspector. UnityEngine.Animator.SetBool (System.String name, System.Boolean value) (at /Users/builduser/buildslave/unity/build/Runtime/Animation/ScriptBindings/Animator.bindings.cs:343) playMyAnimation.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/playMyAnimation.cs:13)" And if I reimport the prefabs on the hierarchy from the assets, the component "Avatar" which I assigned to MyAnimationController disappears. Any idea about how to solve this?
The connections are sometimes lost when you use prefabs, you could always search for the controller manually when you want inside those scripts. I'm not sure if that's helpful or not?
@@SpeedTutor I hope it is, I'm still not confident in C# and unity to try what you suggest, but today I'll try to work with scriptable objects instead of prefabs to see if something changes. Thanks buddy!
There seems to be a slight delay after you enter the collider and before the animation starts. What's the reason for that? Or am I just not seeing it correctly?
@@Goggalor1990 Sorry, It's been so long so I don't remember. Looking at the video again though, it seems like it may be the animator controller. IIRC, it does some auto-blend thing for blending between animations... in this case it may just be blending from a Stop "animation" to the actual Spinning animation... hence the weird spin-up time and spin-down. Let me know if that helps.
I got a problem with [SerializedField] it tells me i have nothing referenced or something like that. My Code is the same except for the Names, it doesn‘t highlight the code line for the Animator… what am i doing wrong?
Hey, I'm making a game right now that requires a lot of animations that need to be played when entering a trigger, and I mean A LOT when I say a lot. Wouldn't doing this way require me to make a script and animator set up for every single animation I need triggered? If so, is it still possible to do it other ways that will save me the time?
I do have another animation tutorial which you could just call the name of your animation, on the trigger event without this setup! It's on my channel! Just search "Animation".
i tried to do the script in 2d and i got this errore Assets\Playeranimation.cs(13,35): error CS1061: 'Animator' does not contain a definition for 'Setbool' and no accessible extension method 'Setbool' accepting a first argument of type 'Animator' could be found (are you missing a using directive or an assembly reference?)
I have a different tutorial which will show you how to create an animation and play it in code, easier than this one. I think I've linked it in the video description! :)
I have a problem, for some reason my animator doesnt do the transition when i want it to (player needs to click the left mouse button to initialise) the parameter is completed so the condition becomes true but nothing happens within the animator, i am using the mouse button down version of it, any solutions, would mean a lot and thank you!
You could take a look at the newer animation video I've created in a the description and/or pinned comment. I should you how to do it in an even easier way. It might help! :)
I did this and it works but the animation doesn't play at the speed I have it set to. Basically I have a player interact with a switch to lower lava on the ground. When the player interacts with the switch the lava instantly disappears, when in the animation it was slowly going down. Is there a way to have it not be instant?
I even duplicated this script as "PlayMyAnimation2" and input my 2nd animation but it does nothing, is it trying to call from the same animator controller?
It makes private variables visible in the inspector. It's good to keep variables private UNLESS they actually need to be public (Across other scripts) :) - I hope that helps!
5 years later. Using unity 2022.3.43f1 So i dont know if the version has updated and changed so much that this isnt useful anymore However I made my own custom tag of "NPC" instead of player, because the Npc's should not have access to the rest of the luxories and features that the "player" tag has access to. Any time any object with this Custom tag enters an animation trigger. Nothing happens. even after using Debug.Log to see if the trigger is triggered. It seems nothing with any other tag works. I do make sure that it : if(other.CompareTag("NPC")) { Debug.Log("Collideractive"); doorAnimationController.SetBool("openTrigger", true); } but nothing happens. Might you know why? Would it be better if I just remove the Compare tag entirely? and just use if(other) { do the thing }
Works great!!!! I set up 3 colliders with different names to play different animations but when my player collides with the first one it plays all my animations one after the other.I wanted it to play different animations on different colliders positions.:(
Hm for some reason it doesn't like this part: [SerializeField] private Animator myAnimationController; it seams not knowing [SerializeField]. What is wrong?
I have a question: I want to set up a barrier/trigger, so when the player enters it, it makes them turn around and walk away from it (not allowing them to continue in the same direction) would this work for that?
That's a good question, it may work but you'd likely want to put your player on a path which they follow to the point you want to send them back too. Lets say for example, taking input controls away from your players and then translating the character position somewhere else!
@@SpeedTutor I tried that but ran into a problem, for some reason once the animation is done, it cancels out gravity P: Do you know how to make the animation work so that it doesn't tamper in gravity? (So it works same as normal once the animation is over?)
I'd probably say that you don't use an animation to take control of your player, just move your player away manually. Are you doing a 3D game? Third person on Third person?
@@SpeedTutor Yes, I'm doing a 3D game, however this part of the game is in 1st person but still has a model, so the arms and hair are visible. How would I stop the animation from disabling the gravity on the model though? Is there an option for gravity to always be applied to the model, even during animations? Also thank you so much for the fast response too! This is my first game but still a big project and I'm pretty determined to make it the best I can :)
When I place the object in the Animator space in inspector and I play the button to play the game, the space gets empty again. I dont know why does it happen... please help me
Any way to use multiple events through this one script? Using it for elevator doors, got the first floor working, and dont know how to go about adding a second animation with its own new trigger for the second or third floor.
Hi! My iOS app is locking the phone’s screen after 1 minute without clicking on the screen. I started with Unity recently and I’m not a programmer at all. Do you know what I need to do? Thanks!
Did I write something wrong? My code is just straight up not working. There are no errors or warnings when launching the game. I can't see if I wrote something wrong, please help. public class Test : MonoBehaviour { [SerializeField] public Animator myAnimationController; private void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) { myAnimationController.SetBool("playerNear", true); } else { myAnimationController.SetBool("playerNear", false); } } }
@@SpeedTutor For example: in a 3d platformer, there's a plataform where the goal of the game is. And when the player step on it, the character makes a winning animation, like "\o/" . How can i make the animation play from this outside factor within the player on this example?
Again one great tutorial from you [great tutorial = understandable+quick+straight to the point]. Thank you. But I am wondering is it possible to make something like universal script to start anim? What I actually mean is, {bare in mind im totally noob in scripting} instead of -private- thing can we have it -public-? So to use one script for different objects and different animations? Just, you know, there is that Door what have to be open, so I will just drop that script on the door and than drop already made animation from previous door and maybe this door will open not by "player" but by some "rigid body tagged: ball" which I will just drop from the scene in to the specific field in the script in Unity properties panel. I hope you you see what I mean :)
I know exactly what you mean, you could just prefab your door which has the script on it and duplicate that same thing. So it's almost like two copies of the same thing but they would work independantly! :)
Any idea why I can't drag and drop my gameobj into the My Anim Controller slot? Whenever I go into the Hierarchy to select the gameobj and drag it over to the script it's got the infamous prohibited sign?
@@SpeedTutor Thank you first and foremost for the timely reply :D That allowed me to drop the gameobject into the MyAnimController variable slot, but the animation isn't working so I'm going to scrap the project and follow this amazing tutorial again. I know it's def a mistake on y end I just have to figure out what I'm doing wrong. As always keep up the amazing tutorials you're absolutely amazing bro!!!!
@@SpeedTutor Your method helped out a lot and I made good progress, the ONLY last issue I'm having now lol it the warning message in the console. The message states Parameter 'OpenChest' does not exist. UnityEngine.Animator:SetBool(String, Bool)…..When I open the animoator window and physically check the parameter the chest opens, but when I use my char to walk into the trigger I get that warning. Do you think it's my character or broken capsule collider I'm using for my char by chance? This is unfortunately my only issue Unity is so unforgiving lol.
This would be good for traps..quick question..instead of a player walking into the trigger can a object be used? ( a rock on a floor tile for example )
Great tutorial and saved me lots of time researching about animation controllers but I ran through an error for my game. It finishes the animation and only then starts the new animation when my parameter is set to true. Can you cut the animation immediately and start the new one as soon as the bool is set to true? Please help.
How can i get this to play sound along with an animation cus im wanting to make a horror game based on 21 years of reoccurring nightmares which is about up until a year ago im 22 now and turning 23 on the third of October
this is my current code, but the code still doesnt work using System.Collections; using System.Collections.Generic; using UnityEngine; public class Open : MonoBehaviour { [SerializeField] private Animator myAnimationController; private void OnTriggerEnter(Collider other) { if (other.CompareTag("Player") && Input.GetKeyDown(KeyCode.E)) { myAnimationController.SetBool("runclip", true); }
@@SpeedTutor no, I can run the code without the input getkeydown part and have it the same as yours with no problems, but when I try to add that bit it just doesn't function, but no errors. I have tried to make it display a message in the log within the if statement, but it dos not do anything. I have only started using unity about 2 weeks ago but have watched lots of tutorials and at least know the basics. Thank you for your help.
Ah my bad, I know why. If you imagine that "OnTriggerEnter" will only run code once (When you collide with it). To actually do an input event you need a type of method that will be checking if you're instead the trigger at any point. One example you could create a boolean to be set to true when you're in the collider, then in an update method do the input event. But I'd say an easier way would be using "OnTriggerStay" rather than "OnTriggerEnter" - Which is similar to the update method (Checking every frame) but will only check if you're still inside the collider. I hope that helps you out! :)
Hi! I just found your channel and I'm impressed! I have a question if you don't mind, that is, does this work if I only want my animation to trigger once? ( for etc. Book falling from bookshelves by itself) Thanks and keep making good content! :)
@@SpeedTutor That's great to know, I'll try it out then! Thanks for the reply too! I am a beginner so your channel is a really big help! One of the best out there ~ (I mean it)
Nice, you helped me. But I need a little more help and I can't find the answer anywhere, you are the closest to answering me, that's why I'm addressing you. I have a situation where I want my player to be able to use an animation attack only when he picks up a weapon. Before that no (before taking up wepons i want to only uses basic movements,after pick up wepons i want to be able to use attack animation) I don't know if you understand me and if so, would you answer me? Thanks!
You need a different set of states when you have weapons, it could be a different set of animations for the character that are activated when you pick one up. That's a very indepth question. You want to have something that switches states and even state machines with the animations.
Is there some way to make this work with a Raycast? I want to have my player look at an object, press E, and then an animation plays. However, doing the method in this tutorial doesn't seem to work and I don't know why... The raycast works, I have a debug. log telling me that. It's just that the bool is not changing to true for some reason
Have a similar problem with an animation that's supposed to activate on a button press, you don't happen to have solved it yet? Would love to see the solution.
using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayAnotherAnimOnTrigger : MonoBehaviour { [SerializeField] private Animator myAnimationController; private void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) { myAnimationController.SetBool("ChangeAnimationTroley", true); } } } Can you please check .I needed only player with animation (moving troley) to hit the box and change his own animation to hit ....I tweak the scene a little bit but no chance to work it out. Pleae let me know if you have idea what I am doing wrong. Thank You.
Thank you, works like a charm! Although I have a question, is it normal for it to have a delay before playing the animation? I noticed it took like about .5 seconds when you step in the trigger box. I tried for an animation for my door and it also has a delay too. Is there anyway to control it or Unity is doing something in the background?
You could also try changing the 'speed' on your DefaultState to something like 10 so it cycles through faster and reduces the delay getting to the next animation event.
Hey great video! I based my animation off this video but Instead of the player being the trigger on an object, the object is a trigger on the player. When the object hits the player it is destroyed and the bool stays true, i tried using an else statement to keep it false otherwise, but it seems the object being destroyed on the player is keeping the bool to true. Any ideas on how to fix that?
Don't trigger me or I'll throw animation at you! ;)
🔥UNITY SAVINGS: bit.ly/UnitySalesHub
🔥SpeedTutor Unity Store: bit.ly/STUnityStorePuzzlePacks
🔥HUMBLE SAVINGS: bit.ly/HumbleBundleDeals
a trick : watch series at Flixzone. Been using them for watching a lot of movies these days.
@Turner Saint Definitely, been using Flixzone for years myself :D
@Turner Saint yup, have been watching on Flixzone for years myself =)
Tip: If you want your transitions to happen without a delay, uncheck "Has Exit Time" while you have your transition selected in the animator.
That's a heroic tip, thanks for sharing my friend! :D
You are a godsend man. I'm up here for at 1am trying to figure this out for hours for a class demonstration the next morning and I can't thank you enough. Finally works!
I do have another animation tutorial which can make this happen in a line of code which might also help you! :)
@@SpeedTutor Awesome! Will give it a watch.
Do everything as he says exactly and you won't hate yourself
This also works in 2D! I tried this tutorial and at first I struggled a lot because nothing happened and I didn't know what I had done wrong. Then I realized if you are using 2D Colliders etc. you need to change one line of code to make it work: private void OnTriggerEnter2D(Collider2D other)
You're exactly right! :) I do also have a couple of recent tutorials where I show you how to do this in an even easier way! :)
God you need way more views. This is simple and very dynamic within a game. Thanks!!
No problem at all! :)
Thanks after 1 day of research finally found a good toutorial
I'm glad you found this, thanks for watching! :D
Thank you so much!! i found this tutorial after two days of trying to make a working elevator and it made it work!!
Glad I could help!
@SpeedTutor
How can i do this on click?
how would i get the animation to lock in place when it finishes its animation?
I'm trying to make a sliding door.
set the desired final state of obj in another state and keep it as the last one in your animator
I can't get the animation to quit when I leave the box that has the trigger
Thank you very much, it is really useful.
I was thinking of making an animation on my channel and it may help me.😬
Great to hear it, my friend. Good luck! :D
Hi, thanks for the tutorial. I have a problem with the MyAnimationController variable, though. I am using an array of prefabs as collision triggers, if I set the component that MyAnimationController asks through the inspector (as seen at 8:20) on those prefabs (I am assigning it "Avatar", as my Avatar is my player and it's the GameObject on which I want to change the animation on trigger collider with the prefabs), even if I hit "apply all" in the inspector, after I delete the prefabs from the hierarchy (as I only leave their spawner) and I start the game I get this error:
" UnassignedReferenceException: The variable MyAnimationController of playMyAnimation has not been assigned. You probably need to assign the MyAnimationController variable of the playMyAnimation script in the inspector.
UnityEngine.Animator.SetBool (System.String name, System.Boolean value) (at /Users/builduser/buildslave/unity/build/Runtime/Animation/ScriptBindings/Animator.bindings.cs:343) playMyAnimation.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/playMyAnimation.cs:13)"
And if I reimport the prefabs on the hierarchy from the assets, the component "Avatar" which I assigned to MyAnimationController disappears. Any idea about how to solve this?
The connections are sometimes lost when you use prefabs, you could always search for the controller manually when you want inside those scripts. I'm not sure if that's helpful or not?
@@SpeedTutor I hope it is, I'm still not confident in C# and unity to try what you suggest, but today I'll try to work with scriptable objects instead of prefabs to see if something changes. Thanks buddy!
There seems to be a slight delay after you enter the collider and before the animation starts. What's the reason for that? Or am I just not seeing it correctly?
I don't know if you ever figured it out, but if you did please let me know lol. It does have a slight delay, not sure of the reasoning.
@@Goggalor1990 Sorry, It's been so long so I don't remember. Looking at the video again though, it seems like it may be the animator controller. IIRC, it does some auto-blend thing for blending between animations... in this case it may just be blending from a Stop "animation" to the actual Spinning animation... hence the weird spin-up time and spin-down.
Let me know if that helps.
I got a problem with [SerializedField] it tells me i have nothing referenced or something like that. My Code is the same except for the Names, it doesn‘t highlight the code line for the Animator… what am i doing wrong?
It needs to be [SerializeField] without the "D" :)
Hey, I'm making a game right now that requires a lot of animations that need to be played when entering a trigger, and I mean A LOT when I say a lot. Wouldn't doing this way require me to make a script and animator set up for every single animation I need triggered? If so, is it still possible to do it other ways that will save me the time?
I do have another animation tutorial which you could just call the name of your animation, on the trigger event without this setup! It's on my channel! Just search "Animation".
@@SpeedTutor dude that just saved my life, thanks. That should speed up the developing process quite a bit
I'm happy to hear it! :) You watched the older one?
@@Snikabarz which video was it? i really need it!!!
5:15 when I press the + button it doesn't show any layer types, it just adds a layer. what should I do?
You need to click on the Parameters tab, not the Layers tab. You're adding a bool as a Parameter and not as a Layer.
Hi! Great tutorial, I have been using it a lot in my game. How do you make the animation only play once when you enter the trigger?
You can also check out my newer tutorials on this, which may help you out even easier! :)
wow thx! you teached me how to use unity animations fully!
Glad to hear that!
It work very well on my zombie animation thank you
Great to hear it! :D
Great tutorial, well done. If I am using an arcamera to trigger would I need to change "player" to "arcamera" in the script?
No, no - You can keep it as player! :)
@@SpeedTutor even though my ar camera is labeled "Maincamera"
I would be triggering with the ar camera
@@SpeedTutor do you have a tutorial for adding sound as an event in the annimation?
For example what if I want to trigger 10 vens on one trigger. How do I do that?
i tried to do the script in 2d and i got this errore
Assets\Playeranimation.cs(13,35): error CS1061: 'Animator' does not contain a definition for 'Setbool' and no accessible extension method 'Setbool' accepting a first argument of type 'Animator' could be found (are you missing a using directive or an assembly reference?)
I have a different tutorial which will show you how to create an animation and play it in code, easier than this one. I think I've linked it in the video description! :)
Hi, if animation tag.target get destroyed? animation stuck and play forever, what i should type to make animation stop when tag.target get destroyed?
I'm not really sure as this isn't something I've looked into before :(
Thank you so much! I was using to stop trigger with else but now realized I d had to exit :)
Glad I could help! I do have another tutorial on playing animations on trigger, which is easier and more recent! :)
@@SpeedTutor Thank you i will watch it
Thanks so much. I was about to quit. New sub!!
Haha! You're very welcome, I'm glad you didn't quit. What are you creating?
I want to trigger a death animation on hitting an obstacle in my endless running game, will you please help
I have a new tutorial about this, which might help! :) Its in the description.
plz man tell me bro haw can i just make a ui button witch rotate my car backward and forward
underrated channel
Thanks man! :)
I would love seeing a animation tutorial ive tried to get into it but every time i do i struggle with learning how to animate stuff.
What sort of things do you struggle to animate?
Did the scripting part change, it doesn't autofill like your video..
Does the autofill work for you, nromally?
I have a problem, for some reason my animator doesnt do the transition when i want it to (player needs to click the left mouse button to initialise) the parameter is completed so the condition becomes true but nothing happens within the animator, i am using the mouse button down version of it, any solutions, would mean a lot and thank you!
You could take a look at the newer animation video I've created in a the description and/or pinned comment. I should you how to do it in an even easier way. It might help! :)
Thank you, you hero and saint of a man
I am glad to be of service to you my friend! :D
OMG Thanks! I have been trying to figure this out for so long!
Glad I could help! :)
I did this and it works but the animation doesn't play at the speed I have it set to. Basically I have a player interact with a switch to lower lava on the ground. When the player interacts with the switch the lava instantly disappears, when in the animation it was slowly going down. Is there a way to have it not be instant?
I'm not really sure about that one, can you purposely slow the animation down?
I am unable to drag and drop my animation controller into my script component. Do why this could be?
Any errors?
Could you do a door tutorial?
I'll see what I can do! :)
I even duplicated this script as "PlayMyAnimation2" and input my 2nd animation but it does nothing, is it trying to call from the same animator controller?
Hi, I am doing that player trigger the bomb, then explosion animation occur, the concept is same with this ?
Absolutely! :)
Works great, thank you!
You're welcome!
Just a curiosity in the script: Why did you use [SerializeField] and private, instead of a public variable? :)
It makes private variables visible in the inspector. It's good to keep variables private UNLESS they actually need to be public (Across other scripts) :) - I hope that helps!
5 years later. Using unity 2022.3.43f1
So i dont know if the version has updated and changed so much that this isnt useful anymore
However
I made my own custom tag of "NPC" instead of player, because the Npc's should not have access to the rest of the luxories and features that the "player" tag has access to.
Any time any object with this Custom tag enters an animation trigger. Nothing happens. even after using Debug.Log to see if the trigger is triggered. It seems nothing with any other tag works.
I do make sure that it :
if(other.CompareTag("NPC"))
{
Debug.Log("Collideractive");
doorAnimationController.SetBool("openTrigger", true);
}
but nothing happens. Might you know why?
Would it be better if I just remove the Compare tag entirely? and just use
if(other)
{
do the thing
}
Works great!!!! I set up 3 colliders with different names to play different animations but when my player collides with the first one it plays all my animations one after the other.I wanted it to play different animations on different colliders positions.:(
That shouldn't happen, but I do have a tutorial which is updated from this. It's in the description which might help you! :)
i want to implement it on a moving a character
Hm for some reason it doesn't like this part: [SerializeField] private Animator myAnimationController; it seams not knowing [SerializeField]. What is wrong?
Is there an error before or after that?
I have a question:
I want to set up a barrier/trigger, so when the player enters it, it makes them turn around and walk away from it (not allowing them to continue in the same direction)
would this work for that?
That's a good question, it may work but you'd likely want to put your player on a path which they follow to the point you want to send them back too. Lets say for example, taking input controls away from your players and then translating the character position somewhere else!
@@SpeedTutor I tried that but ran into a problem, for some reason once the animation is done, it cancels out gravity P:
Do you know how to make the animation work so that it doesn't tamper in gravity? (So it works same as normal once the animation is over?)
I'd probably say that you don't use an animation to take control of your player, just move your player away manually. Are you doing a 3D game? Third person on Third person?
@@SpeedTutor Yes, I'm doing a 3D game, however this part of the game is in 1st person but still has a model, so the arms and hair are visible.
How would I stop the animation from disabling the gravity on the model though? Is there an option for gravity to always be applied to the model, even during animations?
Also thank you so much for the fast response too! This is my first game but still a big project and I'm pretty determined to make it the best I can :)
Rather than doing this, could you just enabled a new camera which moves instead of your players? Then give control back to the original player?
When I place the object in the Animator space in inspector and I play the button to play the game, the space gets empty again. I dont know why does it happen... please help me
I'm not sure, any errors?
@@SpeedTutor the problem was that I put "anim = GetComponent();" when it resets the Animator component when play the game. i've fixed it
Playing Animation on Trigger (With one line of code): ruclips.net/video/kqBGg6Rme10/видео.html&
Any way to use multiple events through this one script? Using it for elevator doors, got the first floor working, and dont know how to go about adding a second animation with its own new trigger for the second or third floor.
Why not add two to the same script?
Man! You are a legend! Thank you very much!
You're very welcome!
does this also work with just a collider or do you need to have a cube showing
Just with a collider!
You forgot something... when i clic on conditions, it says "Parameter does not exist in Controller".... so ?
hey can you tell me how you made all of your text soo small for me its all so big that i dont have enough room any more
pls help
What text are we talking about? Text in VisualStudio? (If so) Hold Ctrl + Scroll with your mouse wheel! :)
@@SpeedTutor the text in unity
You can either increase your Windows 10 default scaling OR change Unity's text size in preferences. I have a video on that too! :)
Ok thx
Verry fast reply wow thx
No worries at all! :)
Hi! My iOS app is locking the phone’s screen after 1 minute without clicking on the screen. I started with Unity recently and I’m not a programmer at all. Do you know what I need to do? Thanks!
This is great but I was kind of hoping for how the "Trigger" parameter works, instead of the bool
I do have a tutorial on creating an animation on a trigger with one line of code, it's on my channel if you search "Animation"
@@SpeedTutor Thank you! Will watch the video but I think I got it to work anyways :)
No worries at all! :)
You might want to increase the font size for your videos. Can't see shit unless watching in fullscreen.
Nice tutorial bro but i still don't know how to make obj fell when player enter trigger please reply
very good tutorial hope your channel gets big like brackeys keep making tutorials like this
Thanks very much! :)
good tutorial again my friend!
Thanks man, I even have another tutorial which helps you do this in an even easier way. It's in the description of this video :)
@@SpeedTutor take look my demo! ruclips.net/video/5R-dTOhwAn4/видео.html
It is working, thanks! But what if I don't want the animation to be a loop?
You can select the animation itself and untick "LoopTime" I think!
@@SpeedTutor It worked! Thank you so much!!!
Haha, no worries at all! :)
Did I write something wrong? My code is just straight up not working. There are no errors or warnings when launching the game. I can't see if I wrote something wrong, please help.
public class Test : MonoBehaviour
{
[SerializeField] public Animator myAnimationController;
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
myAnimationController.SetBool("playerNear", true);
} else {
myAnimationController.SetBool("playerNear", false);
}
}
}
Do you have any errors?
Awsome to see you back with tutorial :D so this is the mecanic to activate animation state/StateMachine :)
Thanks man! Good to hear from you again! :)
@@SpeedTutor thank you:D
Thanks Worth it bro :) thanks for explaining this simple
I'm really glad you think so, thanks for coming along to check this out! :D
Thank you so much for this, this is the first tut that i've found that works with my set up.
Great to hear it, thanks for watching! :)
doesn't work anymore i can't add this to my controller 8:20
Are you sure you created the correct reference?
Thank you so much dude ❤
You're welcome!
Many thanks m8 u helped me A LOT !!!
I'm glad you think so! I also have an updated tutorial which may help you out too! :) It's in the description.
This is awesome!
And what if i want the animation to be played in the Player instead? =]
I'm not sure what you mean?
@@SpeedTutor For example: in a 3d platformer, there's a plataform where the goal of the game is. And when the player step on it, the character makes a winning animation, like "\o/" . How can i make the animation play from this outside factor within the player on this example?
Again one great tutorial from you [great tutorial = understandable+quick+straight to the point]. Thank you. But I am wondering is it possible to make something like universal script to start anim? What I actually mean is, {bare in mind im totally noob in scripting} instead of -private- thing can we have it -public-? So to use one script for different objects and different animations? Just, you know, there is that Door what have to be open, so I will just drop that script on the door and than drop already made animation from previous door and maybe this door will open not by "player" but by some "rigid body tagged: ball" which I will just drop from the scene in to the specific field in the script in Unity properties panel. I hope you you see what I mean :)
I know exactly what you mean, you could just prefab your door which has the script on it and duplicate that same thing. So it's almost like two copies of the same thing but they would work independantly! :)
I love you.
Ditto! Thanks for watching my friend! :D
Any idea why I can't drag and drop my gameobj into the My Anim Controller slot? Whenever I go into the Hierarchy to select the gameobj and drag it over to the script it's got the infamous prohibited sign?
Does the gameobject you're dragging in have a animator component?
@@SpeedTutor Thank you first and foremost for the timely reply :D That allowed me to drop the gameobject into the MyAnimController variable slot, but the animation isn't working so I'm going to scrap the project and follow this amazing tutorial again. I know it's def a mistake on y end I just have to figure out what I'm doing wrong. As always keep up the amazing tutorials you're absolutely amazing bro!!!!
Thanks man, very best of luck. Yes! Start from the beginning and see if you pick anything up, sometimes it's something some obnoxiously tiny! :)
@@SpeedTutor Your method helped out a lot and I made good progress, the ONLY last issue I'm having now lol it the warning message in the console. The message states Parameter 'OpenChest' does not exist. UnityEngine.Animator:SetBool(String, Bool)…..When I open the animoator window and physically check the parameter the chest opens, but when I use my char to walk into the trigger I get that warning. Do you think it's my character or broken capsule collider I'm using for my char by chance? This is unfortunately my only issue Unity is so unforgiving lol.
I do have another tutorial which talks about playing an animation and it doesn't use this process. I'll try and find it for you! :)
This would be good for traps..quick question..instead of a player walking into the trigger can a object be used? ( a rock on a floor tile for example )
Yes, in exactly the same way. As long as one of the objects has a rigidbody, you could do it in exactly the same way! :)
Great tutorial and saved me lots of time researching about animation controllers but I ran through an error for my game. It finishes the animation and only then starts the new animation when my parameter is set to true. Can you cut the animation immediately and start the new one as soon as the bool is set to true? Please help.
Thank you for this tutorial!
You are very welcome!
How can i get this to play sound along with an animation cus im wanting to make a horror game based on 21 years of reoccurring nightmares which is about up until a year ago im 22 now and turning 23 on the third of October
Just activate tehesong when the animation starts?
What does the Code [SerializeField] do? Why did you use it?
It makes a private variable visible in the inspector, so we don't have to have everything public.
I need help, on the editor the animation works fine but on build the animation doesn't work.
That's strange, has anyone reported this issue online?
Increadibly healpful. Thank you!
That's no worries! Thanks for coming along to watch my friend! :)
script class cannot be found.. I guess there's no easy way around this..
Also even with the default state set as entry, the animation still plays...
Is the script name the same as your class name?
how could I make the player press the e key once inside the collider to run the animation?
this is my current code, but the code still doesnt work
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Open : MonoBehaviour {
[SerializeField] private Animator myAnimationController;
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player") && Input.GetKeyDown(KeyCode.E))
{
myAnimationController.SetBool("runclip", true);
}
}
private void OnTriggerExit(Collider other)
{
if (other.CompareTag("Player"))
{
myAnimationController.SetBool("runclip", false);
}
}
}
Any errors because it looks like it should work?
@@SpeedTutor no, I can run the code without the input getkeydown part and have it the same as yours with no problems, but when I try to add that bit it just doesn't function, but no errors. I have tried to make it display a message in the log within the if statement, but it dos not do anything. I have only started using unity about 2 weeks ago but have watched lots of tutorials and at least know the basics. Thank you for your help.
Ah my bad, I know why. If you imagine that "OnTriggerEnter" will only run code once (When you collide with it). To actually do an input event you need a type of method that will be checking if you're instead the trigger at any point. One example you could create a boolean to be set to true when you're in the collider, then in an update method do the input event.
But I'd say an easier way would be using "OnTriggerStay" rather than "OnTriggerEnter" - Which is similar to the update method (Checking every frame) but will only check if you're still inside the collider. I hope that helps you out! :)
@@SpeedTutor Thanks a lot!! It works now.
Thanks bro, Really appreciate it.
That's no problem at all! :)
Hi! I just found your channel and I'm impressed! I have a question if you don't mind, that is, does this work if I only want my animation to trigger once? ( for etc. Book falling from bookshelves by itself) Thanks and keep making good content! :)
Yes of course! :)
@@SpeedTutor That's great to know, I'll try it out then! Thanks for the reply too! I am a beginner so your channel is a really big help! One of the best out there ~ (I mean it)
Thanks very much! :) I really appreciate it!
Nice, you helped me. But I need a little more help and I can't find the answer anywhere, you are the closest to answering me, that's why I'm addressing you. I have a situation where I want my player to be able to use an animation attack only when he picks up a weapon. Before that no (before taking up wepons i want to only uses basic movements,after pick up wepons i want to be able to use attack animation) I don't know if you understand me and if so, would you answer me? Thanks!
You need a different set of states when you have weapons, it could be a different set of animations for the character that are activated when you pick one up. That's a very indepth question. You want to have something that switches states and even state machines with the animations.
How can I Triggeranimetion when certain audio is playing ?
Create a script which activates when an audio clip starts, then play the animation?
@@SpeedTutor I am lack of exp. when it comes to coding if you are available, can you please send any example that I can change little bit
how do i only make the animation play once?
Select your animation and untick "Loop"?
@@SpeedTutor i did, and it still did it, it was just error in my code and i fixed it :)
Awesome, what was the error? Haha.
Nice, could find several uses for this little gem :)
Great to hear it, thanks for watching! :)
Is there some way to make this work with a Raycast? I want to have my player look at an object, press E, and then an animation plays. However, doing the method in this tutorial doesn't seem to work and I don't know why... The raycast works, I have a debug. log telling me that. It's just that the bool is not changing to true for some reason
Have a similar problem with an animation that's supposed to activate on a button press, you don't happen to have solved it yet? Would love to see the solution.
thank you so much bro love you from india
You're very welcome, my friend! :)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayAnotherAnimOnTrigger : MonoBehaviour
{
[SerializeField] private Animator myAnimationController;
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
myAnimationController.SetBool("ChangeAnimationTroley", true);
}
}
}
Can you please check .I needed only player with animation (moving troley) to hit the box and change his own animation to hit ....I tweak the scene a little bit but no chance to work it out. Pleae let me know if you have idea what I am doing wrong. Thank You.
Check out my recent tutorial on playing animations, it might be even easier for you! :)
@@SpeedTutor hmm... So many videos... Can You please give me link. Thank You
You're a life saver man, thanks a lot
No problem at all, glad I could help! :)
Thank you, works like a charm! Although I have a question, is it normal for it to have a delay before playing the animation? I noticed it took like about .5 seconds when you step in the trigger box. I tried for an animation for my door and it also has a delay too. Is there anyway to control it or Unity is doing something in the background?
I do also have another tutorial on playing animation which might also be helpful for you! ruclips.net/video/kfXTzAa9G4g/видео.html
@@SpeedTutor thanks a lot, this is perferct.
Great to hear it! :)
You could also try changing the 'speed' on your DefaultState to something like 10 so it cycles through faster and reduces the delay getting to the next animation event.
I hope next time you write the script, maybe you can zoom or enlarge it a bit so maybe some of us will see the script more clearly, thank you
I'll keep this in mind, thanks! :)
Good job. You can also turn off the mesh renderer to give the player the illusion of it being automatic.
Thank you, God bless you.
Awesome ❤❤
Thanks for watching, how did you find me?
thank you so much bro
No problem at all! :D
Hey great video!
I based my animation off this video but Instead of the player being the trigger on an object, the object is a trigger on the player. When the object hits the player it is destroyed and the bool stays true, i tried using an else statement to keep it false otherwise, but it seems the object being destroyed on the player is keeping the bool to true. Any ideas on how to fix that?
When you destroy the trigger, make sure you to turn the bool to false!
does should work with unity 2017 ? or specific to 2018 ? can you do one with timeline
It would easily work with Unity 5 / 2017 / 2018 and onwards.
@@SpeedTutor off topic any chance to make a tutorial how to add rumble when player get hit or enter a trigger ?
Where is the script? for trigger
It's right in the video :) Or I do have a tutorial to play animations in an even easier down in the description :)
Thank You So Much...
No problem at all, I do also have an even easier tutorial which you can checkout too! :D
@@SpeedTutor Sure I will... Telling the truth, I have been looking for this function from months until I got your video on YT...😁😁😁🤩🤩🤩
Awesome! Glad I could help you out. Good luck with your projects! :D
@@SpeedTutor TYSM...‼😁