Unity - Enemy Follows Player [Beginner Tutorial]

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 ม.ค. 2025

ความคิดเห็น • 339

  • @mr.jeffjeffun1212
    @mr.jeffjeffun1212 4 ปีที่แล้ว +1

    you don't know how much I appreciate the fact that you gave the code from the tutorial possible to copy (great tutorial).

  • @j.a.m.s6340
    @j.a.m.s6340 3 ปีที่แล้ว

    tysm i have been looking for this and watched numerous videos but nothing worked but yours did!

  • @antsinpantsninja6619
    @antsinpantsninja6619 5 ปีที่แล้ว +35

    Awesome video. Need more of these short simple tutorials out there. Thank you for not making this into a 20 min video.

  • @tsivilsඞ
    @tsivilsඞ 2 ปีที่แล้ว

    You're a life saver I don't know coding much at all but i am making a game using youtube tutorials lol. I had gotten my enemies following my player but they were always looking the wrong way now I've got my answer and can go fix it now!

  • @-workout4118
    @-workout4118 4 ปีที่แล้ว +3

    Hi, I am from Russia, thanks for the understandable and useful video tutorials, very informative!

  • @karwannouri8266
    @karwannouri8266 4 ปีที่แล้ว +1

    Thank you for this tutorial. Your voice, the speed and the way you speak is great. The information was very valuable but you present everything really well. Thank you!

  • @savecandy6881
    @savecandy6881 5 ปีที่แล้ว +8

    Thanks bro I love how you write codes

  • @meg1a445
    @meg1a445 4 ปีที่แล้ว +3

    i cant belive there is people in this world that are trying to help,i couldnt belive that discription man keep it up you just got a subscriber.
    btw do you have any tutorials about enemy spawning on random locations?

  • @brianrobson8864
    @brianrobson8864 2 ปีที่แล้ว +2

    Muito obrigado meu passeiro, estava procurando esse tipo de rotação no inimigo quando ele estivesse seguindo o player e olhasse para o alvo... busquei busquei e apareceu seu vídeo, muito obrigado msm, me ajudou muito...

  • @Just_Chuk
    @Just_Chuk 4 ปีที่แล้ว +1

    Your tutorials are well made and explain unity's mechanics well. Thank you and keep making more videos.

  • @AbdulRahman-vt4bw
    @AbdulRahman-vt4bw 5 ปีที่แล้ว +7

    Very cool, thank you for making this tutorial

  • @MathUniversity1.0
    @MathUniversity1.0 3 ปีที่แล้ว +4

    3:55 this solution worked for me: using 'Rb.rotation = -angle + 180f' instead of 'Rb.rotation = angle'

    • @Historyan
      @Historyan 3 ปีที่แล้ว +1

      thanks!!

    • @tsivilsඞ
      @tsivilsඞ 2 ปีที่แล้ว +1

      You helped me a year later far more than you can know. I thank you. I don't know coding really but im trying to release a game by next week and you are part of the reason I'll be able to do that.

  • @thejamesgreensill
    @thejamesgreensill 5 ปีที่แล้ว +5

    Thank you, been trying to figure out a way to do this using physics rather then Transform.

  • @JxD01
    @JxD01 5 ปีที่แล้ว +42

    Your codes are Sooo EZ for everyone Thanks for this powerful tutorial 😋 please make a video on multiplayer system

    • @klarnorbert
      @klarnorbert 5 ปีที่แล้ว +1

      Add some obstacles between the player and the enemy, and this method breaks.

    • @EnderElectrics
      @EnderElectrics 5 ปีที่แล้ว +1

      @@klarnorbert i guess

    • @lunamnauta5844
      @lunamnauta5844 4 ปีที่แล้ว

      @@klarnorbert A* is fairly easy to learn, and works great if you have obstacles

    • @gone192
      @gone192 4 ปีที่แล้ว +5

      @@klarnorbert What I've found in a lot of the tutorials on TH-cam is the skeleton of the mechanic a developer wants to create. Like I used this and it didn't work exactly like I needed it to, so I iterated on it. So yes, this isn't the best, but it is a damn good starting place for those who don't know how to do it.
      -
      And to anyone reading this, don't forget to stress critical thinking and creative problem solving. Don't take this tutorial as the end result but as the beginning theory for the end result. If it doesn't behave like you want to, iterate on it or find work arounds. You. Are. The. Developer.
      -
      And don't think I'm some great programmer looking down, I know it's hard, I've been programming for a collective two weeks so far. Just have the confidence to iterate on these skeletons of mechanics.

    • @danielholth
      @danielholth 4 ปีที่แล้ว +1

      @@gone192 Spot on :)

  • @akuzanugraha4339
    @akuzanugraha4339 5 ปีที่แล้ว +2

    This is very good channel for Unity Tutorial... Thanks for the tutorial dude.. you awesome!!!!

    • @pressstart6864
      @pressstart6864  5 ปีที่แล้ว

      Nah you’re awesome for taking the time out to give feedback. And positive feedback at that. Cheers my friend, it’s people like you that keep me going

  • @ApexArtistX
    @ApexArtistX 3 ปีที่แล้ว

    Your tutorial makes sense. Now I learn vector to degrees conversion. And I understand

  • @avisekch
    @avisekch 4 ปีที่แล้ว

    Lovely Mr. Waldo. Thank you very much for such short and to the point tutorial.

  • @eekturk4258
    @eekturk4258 3 ปีที่แล้ว +3

    Great tutorial! I am making a game about a circle with a gun fighting against other shapes with guns for no reason and the follow worked perfectly, it really fits to my game.

  • @bluestripes6037
    @bluestripes6037 5 ปีที่แล้ว +6

    You're a great guy. Thank you.

  • @TortoRacoon
    @TortoRacoon 4 ปีที่แล้ว +1

    Thank you! I did it completely different but your logic helped me figure it out

  • @AfterBirth
    @AfterBirth 4 ปีที่แล้ว

    subscribed bcox u provided script easily

  • @ErtBaran
    @ErtBaran 4 ปีที่แล้ว +1

    Thanks soo much. I understand in the end. 💯 Drawing angles and positions was so helpful.

  • @xTheYeTiChannel
    @xTheYeTiChannel 5 ปีที่แล้ว +1

    Your tutorials are very nice & understandable, i like you!

  • @Gooseguy1000-1
    @Gooseguy1000-1 2 ปีที่แล้ว +1

    This video is simple and really shows you how to quickly set up the enemy movement, which is great. However, I'm still really new to Unity, so I would like to learn about what each function specifically is and does to know how it all fits together. Otherwise I'd probably be watching these same basic tutorials over and over again throughout my entire game dev career, which isn't ideal.

    • @brunodesyeux
      @brunodesyeux 2 ปีที่แล้ว

      just search up tutorials for the things you find hard

  • @damirshabayev344
    @damirshabayev344 4 ปีที่แล้ว +18

    can u make a vid with an enemy following the player 3d please.

  • @sebastianurciuolo6249
    @sebastianurciuolo6249 4 ปีที่แล้ว +3

    You should use navmesh agent unless your game level is just an empty desert. And teach a way to implement this in a way where we don't calculate distance every frame on each enemy

  • @rrlosabio7190
    @rrlosabio7190 4 ปีที่แล้ว

    BRACKEYS QUIT SO UR MY SECOND BEST TUTORIAL FOR ME UR EZ TO UNDERSTAND COMPARE TO OTHER EXISISTING,, KEEP BRO HOPE YOUR CHANNEL GROW FAST

    • @Plapp_
      @Plapp_ 3 ปีที่แล้ว

      calm down captain caps lock

  • @Ben-qn3py
    @Ben-qn3py 5 ปีที่แล้ว +3

    You're amazing man!

  • @-Dolphus
    @-Dolphus 4 ปีที่แล้ว

    Yo dude, thanks for the help. I changed your script to fit min tho, so it's not completely the same. But thanks to you, I got inspiration for a way to fix my issue, which was rotation of the enemy towards player.position.

  • @wojciechbecela5550
    @wojciechbecela5550 3 ปีที่แล้ว

    That's exactly what I was looking for!
    Thanks a lot!

  • @hhashh2327
    @hhashh2327 4 ปีที่แล้ว

    Awesome video! Saved my life!

  • @EricEwers
    @EricEwers 5 ปีที่แล้ว +16

    Excellent tutorial! How would I go about making this for a 3D object? I added a Rigidbody to my enemy object and changed Rigidbody2D to Rigidbody in the code.
    I am getting the error: " Cannot implicitly convert type 'float' to 'UnityEngine.Quaternion' "

    • @pressstart6864
      @pressstart6864  5 ปีที่แล้ว +6

      A RigidBody2D.rotation uses a float value, but a RigidBody.rotation (3D) needs a Quaternion value. This might help:
      www.cuelogic.com/blog/how-to-rotate-object-in-unity-using-quaternion

    • @mandalapratama7907
      @mandalapratama7907 5 ปีที่แล้ว

      Nice info thanks im from indonesia

    • @user-qd9jn5od7v
      @user-qd9jn5od7v 4 ปีที่แล้ว +9

      simply use this code
      rb.rotation = Quaternion.Euler(0f,angle,0f);

    • @MrChocofreak
      @MrChocofreak 4 ปีที่แล้ว

      @@user-qd9jn5od7v trying this in vr on a regular capsule, it disappears before its ever visible in headset. any explanation or help?

    • @camelusvolantes3326
      @camelusvolantes3326 3 ปีที่แล้ว

      @@user-qd9jn5od7v Thx bro.

  • @quimerico
    @quimerico 3 ปีที่แล้ว

    Awesome video, very clear and simple :}

  • @CodesnippetBiz
    @CodesnippetBiz 4 ปีที่แล้ว

    very good tutorial, nice and simple! I love it!

  • @melisaappaof944
    @melisaappaof944 3 ปีที่แล้ว

    I get the error CS0029: Cannot implicitly convert type 'float' to 'UnityEngine.Quaternion' for the code at min 3:45 help

  • @3oriigingaming
    @3oriigingaming 4 ปีที่แล้ว +5

    I haven't tried this yet but if I do, I think I'll eventually face an issue where the enemy will collide with other static objects instead of simply moving around them. Maybe using a NavMesh would be preferrable.

  • @danlapersy5099
    @danlapersy5099 4 ปีที่แล้ว

    Thank you so much Press, you are awesome with this video you help me alot .

  • @foreducation408
    @foreducation408 2 ปีที่แล้ว

    this video is awesome, helped me soo much.

  • @GamingWarlord64
    @GamingWarlord64 5 ปีที่แล้ว +2

    Never mind i got it Thank you i have been trying to do this all day if your trying to do this on a 3D place do Vector 3 not 2 that's all.

    • @astrabajtyt
      @astrabajtyt 5 ปีที่แล้ว

      You don't need to use Vector2 at all really, you might use this code, its a bit easier I think:)
      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;

      public class NewFollower : MonoBehaviour
      {
      [SerializeField] Transform target;
      float moveSpeed = 4f;
      Rigidbody2D rb;
      Vector3 direction;
      void Start()
      {
      rb = GetComponent();
      }

      void Update()
      {
      direction = target.position - transform.position;
      float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
      rb.rotation = angle;
      }

      private void FixedUpdate() {
      Move();
      }

      void Move(){
      rb.MovePosition(transform.position + (direction.normalized * moveSpeed * Time.deltaTime));
      }
      }

  • @crio9604
    @crio9604 3 ปีที่แล้ว +2

    You could also just define a lookDir Vector ( transform.right ) and do transform.right = player.transform.position - transform.position, so you don't need to calculate angles for rotation.

  • @dehnmagnus
    @dehnmagnus 2 ปีที่แล้ว +2

    A tip. If you are using unity 3d u can just say transform.LookAt(player); You are welcome!

  • @legion5548
    @legion5548 4 ปีที่แล้ว

    Thank you, your video helped a lot.

  • @michaelshollaj6428
    @michaelshollaj6428 4 ปีที่แล้ว

    thanks a lot man , it helped me a lot :D

  • @Killerkeller-r6j
    @Killerkeller-r6j 2 ปีที่แล้ว

    I needed this!!!

  • @skarrx2416
    @skarrx2416 4 ปีที่แล้ว +1

    3:45 After inputting this code I got this error: Cannot implicitly convert type `float' to `UnityEngine.Quaternion

    • @Soy_Rafico
      @Soy_Rafico 4 ปีที่แล้ว

      Maybe you are using Rigidbody, this tutorial is for Rigidbody2D. I had the same problem

  • @gametechy702
    @gametechy702 4 ปีที่แล้ว

    Great Tutorial Man! Your channel is the best out there! You got my Like and Sub too!!

  • @bluepie4983
    @bluepie4983 4 ปีที่แล้ว

    That is a very helpful tutroial, thanks

  • @kpv8
    @kpv8 4 ปีที่แล้ว +6

    Is it possible to make enemy to start move towards the player when the player is just in enemy let me name it "seeing range"?

    • @yuqzii
      @yuqzii 4 ปีที่แล้ว

      I know im answering late but you can use Vector3.Distance(position a, position b). that will give you the distance between two objects

    • @felipethepro467
      @felipethepro467 4 ปีที่แล้ว

      ​@@yuqzii I tried this but it isnt working(sorry if its a obvious mistake im a beginner)
      edit: so the more than symbols where backwards..... anyways i found this video that does basically the same thing th-cam.com/video/xppompv1DBg/w-d-xo.html (5:20)time

    • @alanb4098
      @alanb4098 4 ปีที่แล้ว

      OnTriggerEnter2D

  • @vizion4724
    @vizion4724 3 ปีที่แล้ว +1

    2:43 can anyone explain why we have to type "THIS".GetComponent

    • @johnlemon6678
      @johnlemon6678 3 ปีที่แล้ว +1

      @Vizion The "this" keyword refers to the current object executing the code. Since this object inherits from monobehavior it has a method which gets a component. Although it is not required in all cases, you have to use "this" in cases where for example, in a method the argument is named the same as the variable so the compiler has no idea which one you are referring to. So you don't really have to use it in this case. I think he was just keeping what he was doing explicit.

  • @FatherPhi
    @FatherPhi 5 ปีที่แล้ว +3

    I love your videos man, it would be great to interview you one day haha

  • @kumelogames
    @kumelogames 4 ปีที่แล้ว +7

    Hi! I am having an issue with my spawner and enemy AI. every time they spawn they just go straight to the player start position. Both Player and Enemy are prefabs and the enemy doesn't seem to track player movement at all. If anyone can help or offer suggestions that would be great.

    • @randomman2582
      @randomman2582 4 ปีที่แล้ว +1

      make sure your codes are under void update() and not void start()

    • @malaise7110
      @malaise7110 4 ปีที่แล้ว +1

      @@randomman2582 I have the same problem and my code is in the right place

    • @foreducation408
      @foreducation408 2 ปีที่แล้ว +1

      yeh dude i am facing the same problem, still trying to figure that out maybe it's in the code some where, tell me if you found anything

    • @foreducation408
      @foreducation408 2 ปีที่แล้ว +4

      ok so I found the solution for this problem add these lines of code in your script
      private GameObject player;
      private Transform playerTransform;
      player = GameObject.FindGameObjectWithTag("Player");
      playerTransform = player.GetComponent();
      so what we did there is that instead of using transform component we used GameObject
      and then we accessed the transform component by making a private variable called playerTransform,
      so this way first we are getting the player game object by finding the Player tag
      and then we using it's transform component to let the enemy find the position of our player
      hope this will help someone
      final script looks like this
      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      public class Enemy : MonoBehaviour
      {
      public float moveSpeed = 5f;
      private GameObject player;
      private Transform playerTransform;
      private Rigidbody2D rb;
      private Vector2 movement;
      void Start(){
      player = GameObject.FindGameObjectWithTag("Player");
      playerTransform = player.GetComponent();
      rb = GetComponent();
      }
      void Update(){
      Vector3 direction = playerTransform.position - transform.position;
      float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
      rb.rotation = angle;
      direction.Normalize();
      movement = direction;
      }
      private void FixedUpdate(){
      moveCharacter(movement);
      }
      void moveCharacter(Vector2 direction){
      rb.MovePosition((Vector2)transform.position + (direction * moveSpeed * Time.deltaTime));
      }
      }

    • @asdfgasdfg8006
      @asdfgasdfg8006 2 ปีที่แล้ว +1

      @@foreducation408 God bless you.

  • @creeperfreaker3910
    @creeperfreaker3910 4 ปีที่แล้ว +9

    I didn't know you could go quicker than brackeys

  • @mahanfarahani698
    @mahanfarahani698 4 ปีที่แล้ว

    well done and nice job,thanks

  • @EnderElectrics
    @EnderElectrics 5 ปีที่แล้ว +9

    Break when turned into a prefab...?
    Why?

    • @gone192
      @gone192 4 ปีที่แล้ว +3

      I'm sure you've already found a solution but I just wanted to add a quick note here because I'm having the same problem.
      When you turn it into a prefab it loses it's ability to track the players transform. The inspector slot for the player where you drag the player into it 1:55 for some reason can't carry the data into the prefab. I haven't found a solution myself, but in case someone else has this problem, this is what's happening.

    • @thebasic5917
      @thebasic5917 4 ปีที่แล้ว

      @@gone192 did u find a solution yet? im so mad idk what to do lol

    • @gone192
      @gone192 4 ปีที่แล้ว +4

      @@thebasic5917 the //comments are what tell you what to do, best of luck mate
      public class enemyMove : MonoBehaviour
      {
      private Rigidbody2D rb2d;
      //create a separate Rigidbody2D
      private Rigidbody2D rb;
      public float moveSpeed = 2f;
      private Vector2 movement;
      void Start()
      {
      GameObject player2 = GameObject.Find("player");
      //this code finds the player based on it's name in the quotes
      rb = this.GetComponent();
      rb2d = player2.GetComponent();
      //this attaches the found players RB2D to the premade rb2d
      }
      void Update()
      {
      Vector3 direction = rb2d.position - (Vector2)transform.position;
      //replace player.position with rb2d.position
      float angle = (Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg);
      rb.rotation = angle;
      direction.Normalize();
      movement = direction;
      }
      void FixedUpdate()
      {
      moveChar(movement);
      }
      void moveChar(Vector2 direction)
      {
      rb.MovePosition((Vector2)transform.position + (direction * moveSpeed * Time.deltaTime));
      }
      }
      This is how I fixed it, instead of creating a public transform and plugging in the player object, this removes the need to plug in an object to track by finding the object in the game and getting it's RigidBody2D component. Here is the Script API
      docs.unity3d.com/ScriptReference/GameObject.Find.html
      I would look over this and take in the notes/warnings in the beginning, this way of doing it probably isn't the best, however this is just the solution I came up with.

    • @gabehardy-fowler8126
      @gabehardy-fowler8126 4 ปีที่แล้ว

      Jesse thank you man, god bless.

  • @Yiu-wq1yo
    @Yiu-wq1yo 5 ปีที่แล้ว +3

    My best channel Good Work man :D
    Can u make tutorial about Enemies (ranged and Melee) ?

  • @Brekson
    @Brekson ปีที่แล้ว

    3:47 had red underlined under angle in enemyRb.rotation = angle;

  • @ezio2110
    @ezio2110 4 ปีที่แล้ว +1

    Add a -90f after Mathf.Rad2Deg to get the enemy face the player if you can not solve it with the rotation method

  • @pablito4762
    @pablito4762 4 ปีที่แล้ว

    Great tutorial

  • @IjazAhamed-g7u
    @IjazAhamed-g7u 10 หลายเดือนก่อน +1

    Try this code at:3:47 Quaternion angle = Quaternion.Euler(direction.y, direction.x,0);
    rb.rotation = angle;

  • @MerrStudio
    @MerrStudio 4 ปีที่แล้ว +1

    Why does it slow down when coming closer to the player?

  • @Tim_Voronkin
    @Tim_Voronkin 5 ปีที่แล้ว

    thank you very mutch, cool tutorial

  • @dstyx3725
    @dstyx3725 ปีที่แล้ว +2

    Awesome tutorial. However, Unity has been updated and will no longer allow you to drag the player from your hierarchy into the script. To get around this I added this line of code into the start method:
    player = GameObject.Find("Player").transform;
    Just make sure whatever is inside the quotes is the same as what is being used for your player object.

    • @firstshturm
      @firstshturm ปีที่แล้ว

      Hello, how can I make it search by player tag?
      and to make it work as a prefab?

  • @mrkensho3770
    @mrkensho3770 2 ปีที่แล้ว +1

    Hey guys I need help, when I apply the code it works perfectly fine with the enemy, but as soon as I make my enemy a prefab so I can spawn it as a wave they stop following my player. I tried to add the player to the transform player option, but for some reason it wont let me unless it is another prefab object any chance you guys can help me out.

  • @aprimic
    @aprimic 2 ปีที่แล้ว

    Why did you need to do physics 2d for rotation when you have it available in the transform?

  • @minatic1148
    @minatic1148 2 ปีที่แล้ว

    Alternitive code:
    in Class write this:
    public Transform target;
    in Update write following:
    Vector3 relative = transform.InverseTransformPoint(target.position);
    float angle = Mathf.Atan2(relative.x, relative.z) * Mathf.Rad2Deg;
    transform.Rotate(0, 0 , angle);
    Drag ur player into the target field of ur inspector and it should work!

  • @kuma4an
    @kuma4an 5 ปีที่แล้ว +2

    Thanks for script!

  • @Cenji
    @Cenji 4 ปีที่แล้ว +1

    I get this error 'moveSpeed' doesnt exist in the current context

    • @Cenji
      @Cenji 4 ปีที่แล้ว +1

      I found out why but now im getting Operator '+' is ambiguous on operands of type 'Vector3' and 'Vector2'

  • @jmfb789
    @jmfb789 5 ปีที่แล้ว +6

    Isn't it better to use GameObject.FindGameObjectWithTag("Player"); at the start function instead of just dragging the player in the player variable? Awesome Video btw thank you!

    • @pressstart6864
      @pressstart6864  5 ปีที่แล้ว +2

      Yes actually we use that instead in the final project download. Either work honestly, but if you're adding enemies during runtime, your code works better.

    • @chimz8057
      @chimz8057 5 ปีที่แล้ว

      You could, but that requires more processing. Basically the "find" command, no matter by tag or name always uses more process power. So using the Drag and Drop method would take off some load from your game, which becomes vital the more finished and complicated your game becomes (no one likes a game which takes too much process power or lags).

    • @CyberAngel67
      @CyberAngel67 5 ปีที่แล้ว

      @@chimz8057 If it is in Awake or Start that extra processing is neither here nor there and people should be told to NOT use it in Update/FixedUpdate and LateUPdate, but Awake and Start is perfectly fine.

    • @viktorskorpi7624
      @viktorskorpi7624 4 ปีที่แล้ว

      Press Start hi, i tried finding this code but the one on your website only has the code you showed in the video. Can you please share this better code with me? Thanks you

    • @kapprison8624
      @kapprison8624 4 ปีที่แล้ว

      This allows me to make it into a prefab now as I wasn't able to with the drag and drop way.

  • @PEDRO4075
    @PEDRO4075 4 ปีที่แล้ว

    Great job brother. Hope you can do more and more videos and have lots of subs. Thank you ✌️

  • @creationJeuxVideoETtuto
    @creationJeuxVideoETtuto ปีที่แล้ว

    hello from french, dear friend dev.
    thank you so much for tuto, it helped me a lot ^^
    End credits of my game, j will mentionne you and you youtube channel.
    thank you again.

  • @bioman1hazard607
    @bioman1hazard607 4 ปีที่แล้ว +1

    any way to apply this to a 3d game and can you use x and z rather then x and y?

  • @robbiemilkovic2092
    @robbiemilkovic2092 3 ปีที่แล้ว +1

    WHAT DO I DO IF MY ENEMY DOESNT HAVE LIMBS OR ISNT BASED AROUND A GAME OBJECT since i just used 1 single asset for the enemy

    • @tsivilsඞ
      @tsivilsඞ 2 ปีที่แล้ว

      My exact problem. Did u ever figure it out

  • @ManiMods
    @ManiMods 2 ปีที่แล้ว +7

    If your player is a GameObject, instead of player.position, type "GameObject.FindGameObjectWithTag("Player").transform.position" and have your player tagged with player in the inspector

  • @blockido2151
    @blockido2151 3 ปีที่แล้ว +1

    This is amazing! I only have square tho and it wont look at me correctly.

  • @michelknorr4281
    @michelknorr4281 2 ปีที่แล้ว

    Thanks thank thanks! thatsa is the movement methode which works for my project i need, i tried 3-4 movement methods, all of them wasnt the right vor my vision for my game. Thanks!!!!! haha i cry actually xD i dont believe

  • @UdulaRatnayake
    @UdulaRatnayake 3 ปีที่แล้ว

    Nice Explanation!
    Will this script help the enemies to avoid obstacles and follow the player?

  • @rudragoenka4572
    @rudragoenka4572 4 ปีที่แล้ว +1

    for the line rb.rotation = angle, it shows - error CS0029: Cannot implicitly convert type 'float' to 'UnityEngine.Quaternion'

    • @omarzaghdane2002
      @omarzaghdane2002 4 ปีที่แล้ว

      Rudra Goenka Maybe caus your using unity engine quaternion

    • @Batxxrobinwonder
      @Batxxrobinwonder 4 ปีที่แล้ว

      No, I’m not and it still shows it because it is a rotation you are trying to combine with a float and it doesn’t work that way. I don’t know how it works, but it doesn’t work that way.

    • @rudragoenka4572
      @rudragoenka4572 4 ปีที่แล้ว

      @@Batxxrobinwonder then how is it working with the other people following this video?

  • @TechWrathTV
    @TechWrathTV 3 ปีที่แล้ว

    In case of 3D top down shooter? what should be the change?

  • @blockido2151
    @blockido2151 3 ปีที่แล้ว +1

    How to I make this but without rotation like in The binding of isacc.

  • @Just_Chuk
    @Just_Chuk 4 ปีที่แล้ว

    You should make a video on the particle system.

  • @AlphaLul
    @AlphaLul 4 ปีที่แล้ว +1

    How do I make it so the speed isn't relative to the distance from the player?

  • @yograjjawle3294
    @yograjjawle3294 5 ปีที่แล้ว +2

    Very good video. helped me a lot. Can you make a tutorial of damage in unity2D(topdown)?

  • @justbrycefr
    @justbrycefr 2 ปีที่แล้ว

    I don't really know if I have not copy and pasted something or done something wrong but when I press the start button in unity it says "all complier errors have to be fixed before you can enter playmode"

  • @wiindigytp3075
    @wiindigytp3075 4 ปีที่แล้ว +2

    The "Enemy" follows until this quite close, then it starts shaking close the the player, but not actually colliding with it. How can I fix that?

    • @AustenSolvie
      @AustenSolvie 4 ปีที่แล้ว

      I had a similar issue if you disable motion when it gets close enough then it won't do this. The reason for this is that the enemy is changing the angle to angle to angle + 180 constantly when it is so close to 0. You could also disable angle changing when it gets close enough/ destroy the player when the enemy is close enough

    • @cools7uff
      @cools7uff 3 ปีที่แล้ว

      @@AustenSolvie how would you do that

    • @cools7uff
      @cools7uff 3 ปีที่แล้ว

      And why doesn’t his enemy do that

    • @AustenSolvie
      @AustenSolvie 3 ปีที่แล้ว

      @@cools7uff in your code have an if statement so if you enemy is touching the hit box of the player/target it will skip that action.

  • @SlippinGibby
    @SlippinGibby 4 ปีที่แล้ว

    Do you have any way to make this code work for a side scroller instead of a top down game, because whenever I jump in my game the character flies and follows the character, I don’t want it to do that

  • @dashoob504
    @dashoob504 5 ปีที่แล้ว +4

    i dont know what happened but now the enemy moves to the place i start but then just stops there

    • @lainegamin
      @lainegamin 4 ปีที่แล้ว

      YES MY EXACT PROBLEM PLEASE HELP

    • @gone192
      @gone192 4 ปีที่แล้ว

      I had this problem as well. I don't have a solution but I know why it's happening. My guess is you made the enemy in to a prefab, it could no longer track your player so you made a prefab of your player then had the enemy track your player prefab? Problem with that is that the enemy prefab only knows the initial position of the player prefab, and not the current position of the actual player, so the enemy is just going to go towards that position.
      I reckon this is what you did because this is the thought process I had when trying to fix the enemy prefab problem.

  • @rushawngillespie31
    @rushawngillespie31 4 ปีที่แล้ว +1

    This is not working for me... Is it because am not using the top down method

  • @sametayaz4891
    @sametayaz4891 6 หลายเดือนก่อน

    2 minutes ago, an AI helper tool suggested me this video. Dude...

  • @Gabriel-ti2rl
    @Gabriel-ti2rl 5 ปีที่แล้ว +1

    Nice vid

  • @kendarr
    @kendarr 3 ปีที่แล้ว

    I'm applying this to 3D, it works, however, now that i added the follow the gameobject is not rotating anymore

  • @rushawngillespie31
    @rushawngillespie31 4 ปีที่แล้ว +1

    Is there anyway this can work in 2d that's not top down??

  • @MrFaciio
    @MrFaciio 2 ปีที่แล้ว +1

    What do you think about my short script?
    Vector3 direction = player.position - transform.position;
    transform.position += direction * speed * Time.deltaTime;
    transform.right = direction;

    • @bonxd
      @bonxd 2 ปีที่แล้ว

      you are the best

    • @MrFaciio
      @MrFaciio 2 ปีที่แล้ว

      @@bonxd Thanks :)

  • @ImYaxon
    @ImYaxon 4 ปีที่แล้ว

    thanks dude i love u

  • @lainegamin
    @lainegamin 4 ปีที่แล้ว +2

    ok so i have a spawning script and whenever they spawn they go to the start spot, not the player

    • @mohammadaymanebensaid7185
      @mohammadaymanebensaid7185 4 ปีที่แล้ว +2

      Don't use the player prefab in the assets ,
      insead in the Start funtion assign the player in the scene to your script ,
      player = GameObject.FindGameObjectWithTag("Player");
      note that you have to tag your player in the editor with the "Player tag" (click the player in the scene , left top corner of the editor)

    • @ethanh.2622
      @ethanh.2622 4 ปีที่แล้ว

      @@mohammadaymanebensaid7185 that doesnt work for me, this error pops up, "Cannot implicitly convert type 'UnityEngine.GameObject' to 'UnityEngine.Transform' [Assembly-CSharp]csharp(CS002)". what am i doing wrong?

    • @serbaneduard5045
      @serbaneduard5045 4 ปีที่แล้ว +1

      @@ethanh.2622 write in Start function: player = GameObject.FindGameObjectWithTag("Player").GetComponent();

  • @JMacify
    @JMacify 4 ปีที่แล้ว

    Great video but why do you use a Vector3 in a 2d game? Couldnt you just use the Vector2?

  • @AlejandroLetxu
    @AlejandroLetxu 3 ปีที่แล้ว

    How can I make the enemy chase the main character but avoiding walls? Currently I can do it but he doesn't detect the shorter way to reach the main character, he stays blocked at the other side of the wall. Thanks in advance

  • @landonbrown3266
    @landonbrown3266 3 ปีที่แล้ว +1

    I keep getting an error that say "The name 'direction' does not exist in the current context" when Im trying to set my game object to look at the player

  • @abhinawram4014
    @abhinawram4014 ปีที่แล้ว

    HOW CAN I MAKE ENEMY FOLLOW ONLY PLAYER'S ON BUTTON DOWN POSITION?

  • @coswic9128
    @coswic9128 2 ปีที่แล้ว

    isnt it redundant to use Time.deltatime if you are gonna use it in fixed Update?

  • @theo9743
    @theo9743 4 ปีที่แล้ว

    the distance is not updating for some reason, just the initial distance is displayed repeatedly in the Debug Log?

    • @theo9743
      @theo9743 4 ปีที่แล้ว

      It seems to just be using centre(0,0) instead of the location of the player object???