Just a tip: you can also make that HomePosition a child to the Enemy (Skeleton), and in the Start just add homePos.parent = null; It will make HomePosition a seperate object (object without a parent as it is in the video) which will not follow the Enemy. this way you can have a complete prefab, and it will not confuse you with the coordinates in case you add multiple Enemy prefabs.
Thank you for this video. This is my first time im working with unity and generally making a game. You are explaining everything really good! Thank you for awesome videos. Subscribed and liked you xD
Thanks for sharing it. I had the same. But there is a big problem. When the enemy try to follow you if there is an obstruct between your player and the enemy. The enemy can't move because of the obstruct. Will you add more property for it?
@HundredFireGames Wondering if youd be able to help out. Im trying to do something very similar with my game with the enemies, except that I want them to move randomly. My script already works, and thet move like I want them, but as far as applying the proper animations to their movements, Im struggling with the "anim.SetFloat("MoveX", (sticking point here). In your video you subtracted the enemies position by the target position, but with random movement, Id subtract the enemies position by?...or a diff equation all together. Any suggestions by anyone would be greatly appreciated.
Play around with the values maybe ur x and y are different in ur game mine minRange was at 8 Only problem im having is my dude wont go back to his og position lol
If you mean go back home without being jittery then move the enemy to where you actually want him to be, then copy and paste the XY coordinates from his location to the XY coordinates of the home location. That fixed his home jittery issue for me.
How could I do the movement using Velocity rather than transform.position, for the enemy? I used this, but it's not a good solution - the enemy never actually gets to the player, nor to home position, therefore the difference between the vectors is never 0. Also, the greater the distance, the greater the speed - even if multiplied by moveSpeed, the same issue occurs. goblinRigidbody.velocity = new Vector3((target.transform.position.x - transform.position.x), (target.transform.position.y - transform.position.y)); //goblinRigidbody is the Rigidbody2D component on the enemy I think it's a very easy solution which just escapes me, does anyone have any suggestions?
I'm new to this, so if my comment sounds like utter nonsense, feel free to disregard it! =) (Also, I see that your comment is three months old, so hopefully you've figured it out, and maybe this'll help someone reading.) I think there are a couple things that might help: 1) You're just setting the velocity rather than using "MoveTowards()". The reason this method might help you (if it can be applied to velocity on a rigidbody) is because it takes a speed parameter (i.e. "MoveTowards(object 1, object 2, speed"). This might help you travel more evenly. 2) I have a rigidbody on my enemy, but MoveTowards() works fine just managing "transform". Is there a reason that you have to use velocity? I believe velocity considers things like mass, friction, etc, and those may be getting in your way. I'm sure you can set all of these settings to "0", but that sounds like a lot of hassle (compared to just managing "transform.position"). 3) You don't need the difference between the two objects to be zero. The enemy should move when his distance from the character is greater than the minimum distance. If you set the minimum distance (the tutorial has it as "minRange") to, say, 0.5, your enemy will stop ~when he makes contact with the player. Try setting "minRange()": to something other than "0".
Just a tip:
you can also make that HomePosition a child to the Enemy (Skeleton), and in the Start just add
homePos.parent = null;
It will make HomePosition a seperate object (object without a parent as it is in the video) which will not follow the Enemy.
this way you can have a complete prefab, and it will not confuse you with the coordinates in case you add multiple Enemy prefabs.
Thanks!!!!!!!!!!!!!!!!!!!!!!
It helped!
How do u maked ur enemy follow the player?
my script don't show any errors but nothing happend
@@iop313 difference between points. If you still haven't done i can write how i did it
@@gxplay2270 It Ok man The day afther it work
You're like the only guy who wants to see error messages to remove them at the end
And also thanks for the tutorial
When you said: First up, he's moon walking. I laught so hard, Ty for the series even tho you abandon it cuz of the lost :(
Thank you for this video. This is my first time im working with unity and generally making a game.
You are explaining everything really good!
Thank you for awesome videos.
Subscribed and liked you xD
it helps me a lot thanks for sharing
Cool beans man! Really professional intro for such a small channel! Keep up the good work!
Great material my man.
Good Conten. Thanks for the Channel. Happy New year.
Great video!
thank you man you helped me a lot i appreciate it
And you can outsmart him by walking around an obsticle.
Why did you use a Vector3 instead of a Vector2?
Huge ty :)
Thank you so much! Very helpful, like!
Hi man, great work, but is there any way, how make moving around other objects( wall etc...). Thanks :)
What if I just want it to stop and idle in whatever direction it was facing, instead of going back to the home point?
Thanks for sharing it. I had the same. But there is a big problem. When the enemy try to follow you if there is an obstruct between your player and the enemy. The enemy can't move because of the obstruct. Will you add more property for it?
Yea aggred
@HundredFireGames Wondering if youd be able to help out. Im trying to do something very similar with my game with the enemies, except that I want them to move randomly. My script already works, and thet move like I want them, but as far as applying the proper animations to their movements, Im struggling with the "anim.SetFloat("MoveX", (sticking point here). In your video you subtracted the enemies position by the target position, but with random movement, Id subtract the enemies position by?...or a diff equation all together. Any suggestions by anyone would be greatly appreciated.
I uses the maxRange and minRange but the enemy still managed to push my character. How do i fix this?
Play around with the values maybe ur x and y are different in ur game
mine minRange was at 8
Only problem im having is my dude wont go back to his og position lol
how do i make my enemy go back to home position without stacking at walls or objects?
If you mean go back home without being jittery then move the enemy to where you actually want him to be, then copy and paste the XY coordinates from his location to the XY coordinates of the home location. That fixed his home jittery issue for me.
@@nyooman5552 thanks a lot
You were talking kinda slow, so I brought the playback speed to 1.5x and it sounds like someone talking at a normal speed. XD
Omg lol your actually right
How could I do the movement using Velocity rather than transform.position, for the enemy?
I used this, but it's not a good solution - the enemy never actually gets to the player, nor to home position, therefore the difference between the vectors is never 0. Also, the greater the distance, the greater the speed - even if multiplied by moveSpeed, the same issue occurs.
goblinRigidbody.velocity = new Vector3((target.transform.position.x - transform.position.x), (target.transform.position.y - transform.position.y));
//goblinRigidbody is the Rigidbody2D component on the enemy
I think it's a very easy solution which just escapes me, does anyone have any suggestions?
I'm new to this, so if my comment sounds like utter nonsense, feel free to disregard it! =)
(Also, I see that your comment is three months old, so hopefully you've figured it out, and maybe this'll help someone reading.)
I think there are a couple things that might help:
1) You're just setting the velocity rather than using "MoveTowards()". The reason this method might help you (if it can be applied to velocity on a rigidbody) is because it takes a speed parameter (i.e. "MoveTowards(object 1, object 2, speed"). This might help you travel more evenly.
2) I have a rigidbody on my enemy, but MoveTowards() works fine just managing "transform". Is there a reason that you have to use velocity? I believe velocity considers things like mass, friction, etc, and those may be getting in your way. I'm sure you can set all of these settings to "0", but that sounds like a lot of hassle (compared to just managing "transform.position").
3) You don't need the difference between the two objects to be zero. The enemy should move when his distance from the character is greater than the minimum distance. If you set the minimum distance (the tutorial has it as "minRange") to, say, 0.5, your enemy will stop ~when he makes contact with the player. Try setting "minRange()": to something other than "0".