Unity: Flying Enemy

Поделиться
HTML-код
  • Опубликовано: 15 ноя 2024

Комментарии • 56

  • @leonardopalmerini2516
    @leonardopalmerini2516 2 года назад +2

    Excuse me,
    but my Player does not seem to hear the collider and the enemy remains stationary
    Any suggestions?

  • @irsilvags6369
    @irsilvags6369 8 месяцев назад +1

    thanks for the tutorial, i rly like it!

  • @random_precision_software
    @random_precision_software 3 года назад +3

    Nice and easy way of showing it. Good stuff

  • @leonardopalmerini2516
    @leonardopalmerini2516 2 года назад

    I don't have a sprite for the enemy but a skeleton animation of Spine App. ... still a great tutorial.

  • @noobdev6464
    @noobdev6464 11 месяцев назад

    I have implemented your code and disable the returnstartpos wich is what i want.
    but how can i make them wondering around instead of staying stationery when i leave the chase area.
    Also is there a way to make the movement have a ease out while they stop chasing?

    • @RootGames
      @RootGames  10 месяцев назад

      You can use Randon.insideUnitCircle to choose random positions inside the radius of the enemy.

  • @SamanthaDurfee
    @SamanthaDurfee 6 дней назад

    video for flying enemy dash attack please????

  • @haxxeldhewitts
    @haxxeldhewitts 4 месяца назад

    i set the Y position for my enemy to be 180, then when i enter your code, i play the game, the position was like before i set the Y position.

  • @lizardrain2918
    @lizardrain2918 Год назад

    I have no idea why but my player gets stuck on the box collider 2d for the chase trigger. Everything is set to on trigger and my code is fine. But If i place the chase trigger box with enemies it gets them all stuck. If the player touches the box collider 2d he just bounces off. If he is under it and jumps he gets stuck in it.

  • @emilywilkins2922
    @emilywilkins2922 2 года назад +2

    Hey there! Awesome video You just saved me hours lol! I was wondering if you could tell me how to have multiple enemies with their own chase boxes cause right now if I add a new collider and the player enters the area it will just trigger the original enemy who is at a different spot in my level and chase the player. Hope that makes sense.

    • @RootGames
      @RootGames  2 года назад

      When you create a new collider with the ChaseControls script, you need to assign enemies in the inspector (drag and drop enemies you want to be affected).

  • @xDTHECHEMISTx
    @xDTHECHEMISTx 2 года назад

    Do you have anything in the works for "get hit knock back effect? Like castlevania when you get hit by an enemy or jump on them and get knock back effect damage?

    • @RootGames
      @RootGames  2 года назад +1

      I covered that in my course on Udemy/Skillshare 😊

  • @marbiox3199
    @marbiox3199 3 года назад +1

    I have a collider that disables when I crouch and he stops chasing, anyway to fix this?

    • @RootGames
      @RootGames  3 года назад +1

      You need to change the approach a bit. Forget about this big collider. You can add smaller colliders on choke points and there enable chasing. For disabling chasing, maybe detect collision on enemies, when they touch collider on the end of the area, set chase variable to false.

  • @HeroicRealm
    @HeroicRealm 3 года назад +1

    very smart way..keep it up

    • @RootGames
      @RootGames  3 года назад

      Thank you, I will 👍

  • @squeeziejetadore3800
    @squeeziejetadore3800 Год назад

    hello, somehow everything works but the flying enemies don't go back when my player leaves the box collision, is there something i missed?

    • @RootGames
      @RootGames  Год назад

      It can be something in your code or it's a problem with detection. If the detection is the problem, select Rigidbody on the player, and set collision detection to continuous.

  • @NoobProMaster01
    @NoobProMaster01 Год назад

    Your guide is very useful and simple! But i have one last problem is my enemy don't just Idle in one place but keep following me even i got out of the trigger point, it still just won't return to it starting Point but keep track me to death. What should I do to fix it? The Start Point seem not work.

    • @RootGames
      @RootGames  Год назад +1

      Assuming that all is good with the code, maybe add the kinematic rigidbody 2d component on "Chase Trigger" object. Also, on the player in the rigidbody2d settings set "Collision Detection" to Continuous

    • @NoobProMaster01
      @NoobProMaster01 Год назад +2

      @@RootGames I fixed it! Thanks for your advice! Your guide is great! Keep making more guide in the future! Thank you so much!!!!

  • @frideonfriday7725
    @frideonfriday7725 10 месяцев назад

    Hello! How can you make it so the enemy wont overlap player's sprite?

    • @RootGames
      @RootGames  10 месяцев назад

      Hi! Try to add offset to the player (targeted) position. Or just make the movement stop when their colliders/triggers touch.

  • @rynmc5471
    @rynmc5471 Год назад

    hi the chase trigger is not activating the chase when the player enters the box collider

    • @RootGames
      @RootGames  Год назад

      Hi, use "Debug.Log" to detect the problem and see what functions are called. I would first check with debug if the collision between the player and the box trigger is detected.

  • @배문성-w4m
    @배문성-w4m 2 года назад

    I am learning well.
    If it is 3D instead of 2D, where can I edit the script?

    • @RootGames
      @RootGames  2 года назад

      Sorry, but I'm not an expert in 3D games so I wouldn't know 100%. Of course, you need to use 3D colliders and change the code for 3D colliders, the rest of the code should work.

  • @tejaskutal2922
    @tejaskutal2922 2 года назад

    Very Nice
    Can you make patrol enemy but only with distance we choose

    • @RootGames
      @RootGames  2 года назад +1

      I'm not sure that I understand you but try to make a basic patrol enemy that will turn when he detects the wall in front or end of the ground. If you want to manipulate that movement, so that the enemy can't go directly to the wall or to the edge of the ground, you can create triggers that will just collide(detect collision) with enemies. When the enemy enters the trigger, flip him in the code. You can place those triggers anywhere you need. Hope it helps ;)

  • @DrJonesJazzMore
    @DrJonesJazzMore 2 года назад +1

    thanks for the video

  • @ArtificiellPotatismos
    @ArtificiellPotatismos 3 года назад

    I'm having trouble understanding the array in ChaseController script. What excatly are we referring too?

    • @RootGames
      @RootGames  3 года назад +1

      In this case, the array holds a reference to the enemies. Add enemies you want to control to the array. Then we enable/disable chase for each enemy in the array.
      Note that the ChaseController script goes on your trigger collider.

    • @guillermostaudt6452
      @guillermostaudt6452 Год назад

      @@RootGames Sorry I have a similar question, when i put public FlyingEnemy[] enemyArray; in my script unity says that "The type or namespace "FlyingEnemy" could not be found"

    • @RootGames
      @RootGames  Год назад

      @@guillermostaudt6452 Did you name your script "FlyingEnemy"?If you you different script/class name then it goes "YourName[]" enemyArray;

    • @guillermostaudt6452
      @guillermostaudt6452 Год назад

      @@RootGames Yes it was exactly that, thanks!!!

  • @orramitos
    @orramitos 7 месяцев назад

    Great tutorial! I'm having issues with adding animations to the script if possible can you help? 🥲

  • @rafarodriguez4765
    @rafarodriguez4765 2 года назад +1

    Good!

  • @omerkara6517
    @omerkara6517 2 года назад

    how can i find this asset pack?

    • @RootGames
      @RootGames  2 года назад

      This was made for some old game that never saw the light of day, so there is no site to download it from.

  • @iconic2310
    @iconic2310 Год назад

    i have tag player not defined?

    • @RootGames
      @RootGames  Год назад +1

      Create a custom tag or use the tag player. Minute 1:30 in the video.

  • @orcvs6297
    @orcvs6297 3 года назад

    The enemies just freeze after respawning my player clone, how do i fix that?

    • @RootGames
      @RootGames  3 года назад

      This is because the variable GameObject player is null for enemies(since it's destroyed). In the enemy script, we find the "player" in the Start() function and that happens only once, after you destroy it, reference to the player is lost. This approach is for restarting the whole level.
      In your case, you need somehow tell enemies about the new respawned player. My suggestion is to do it in the ChaseControl since you already have the array of enemies. In addition to setting the chase variable to true, you need to pass them an object(player) that has entered the collider.

    • @orcvs6297
      @orcvs6297 3 года назад

      @@RootGames i am kind of new to coding, how to do it?

    • @RootGames
      @RootGames  3 года назад

      In the Flying Enemy script make this function.
      public void FindPlayer(GameObject newPlayer)
      {
      player = newPlayer;
      }
      In the Chase Control script, call that function in the foreach loop like this:
      foreach (FlyingEnemy enemy in enemyArray)
      {
      enemy.chase = true;
      enemy.FindPlayer(collision.gameObject);
      }

    • @orcvs6297
      @orcvs6297 3 года назад

      @@RootGames thank you so much, this works on prefabs right?

    • @orcvs6297
      @orcvs6297 3 года назад +1

      nevermind, it's working. thanks again!!!

  • @maurosanchez1540
    @maurosanchez1540 3 года назад +2

    goood!!!

  • @vylan903
    @vylan903 2 года назад

    How would I set up the chase control if I am doing an infinite runner and enemies are getting cloned?

    • @RootGames
      @RootGames  2 года назад

      Trigger colliders need to be a part of the enemy prefab that you will instantiate, or just make them follow the player by default when instantiated, you can find the player with some tag and pass its position

  • @songediter9101
    @songediter9101 3 года назад +2

    can you please share the codes so we don't make any mistake when we copy it?

    • @RootGames
      @RootGames  3 года назад +5

      I don't believe that copy-paste is a good way of learning to code. You will learn much more if you do it yourself step by step and understand the process and logic behind the code. Try it, this is a fairly easy challenge :)

    • @songediter9101
      @songediter9101 3 года назад +1

      @@RootGames thank you for replying

  • @denisoktaviano1337
    @denisoktaviano1337 Год назад

    bro can u help me with this problem 😅
    ChaseControler.cs(24,17): error CS0103: The name 'enemy' does not exist in the current context

  • @TheDumbDonkey
    @TheDumbDonkey 9 месяцев назад

    For me the flip method wasnt working so i asked chatgpt and did it this way and it worked
    private void Flip()
    {
    if (transform.position.x > player.transform.position.x)
    {
    transform.localScale = new Vector3(-1, 1, 1); // Flip horizontally
    }
    else
    {
    transform.localScale = new Vector3(1, 1, 1); // Reset scale
    }
    }