DUDE YOUR TUTORIALS ARE SO EASY TO LEARN! THANKS A LOT. MOST TUTORIALS ON UA-cam ARE QUITE COMPLICATED FOR ME. BUT YOUR'S IS JUST SO WELL MADE THAT EVEN SHIT LIKE ME CAN UNDERSTAND IT! THANKS SO MUCH!!!!!!
Blackthornprod Woooooow. I cant believe you actually noticd me! I really like your videos sir. its really helpin me out. If its ok. Can you make more tutorials about ai?
Im more shitter than you that i couldn't understand it in first time watching 😢. Gotta watch it a few more times and start writing the code on my computer to learn it
Spent around 2 minutes trying to figure out what the heck a "project tile" was. Haha, great tutorial man, making my first fully finished game, a mini space shooter, and this helped out alot. You and Brackys are awesome.
for anyone doing this in 3d, here is the modified script: using System.Collections; using System.Collections.Generic; using UnityEngine; public class EnemyBehavior : MonoBehaviour { public float speed; public float stoppingDistance; public float retreatDistance; public GameObject bullet; public Transform player; private float timeBtwShots; public float startTimeBtwShots; // Start is called before the first frame update void Start() { player = GameObject.FindGameObjectWithTag("Player").transform; timeBtwShots = startTimeBtwShots; } // Update is called once per frame void Update() { if (Vector3.Distance(transform.position, player.position) > stoppingDistance) { transform.position = Vector3.MoveTowards(transform.position, player.position, speed * Time.deltaTime); } else if (Vector3.Distance(transform.position, player.position) < stoppingDistance && Vector3.Distance(transform.position, player.position) > retreatDistance) { transform.position = this.transform.position; } else if (Vector3.Distance(transform.position, player.position) < retreatDistance) { transform.position = Vector3.MoveTowards(transform.position, player.position, -speed * Time.deltaTime); } if (timeBtwShots
The clarity, simplicity and straight forward approach in the tutorial shows that you are someone who has made many games! Thanks for sharing your knowledge.
This tutortial is really good! I actually made a better version (in my opinion) of the movement. public GameObject target; float distance; public float speed; void Update() { distance = Vector3.Distance(gameObject.transform.position, target.transform.position) - 6.5f; (higher = enemy stays farther away, can be anything) speed = distance; transform.position = Vector2.MoveTowards(transform.position, target.transform.position, speed * Time.deltaTime); } This makes it so that the enemy speeds up depending on how far away the player is form the enemy.
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Enemyshooting : MonoBehaviour { public float speed; public float stoppingDistance; public float retreaDistance;
private float timeBtwShots; public float startTimeBtwShots; public Transform player; public GameObject projectile; // Start is called before the first frame update void Start() { player = GameObject.FindGameObjectWithTag("Player").transform; timeBtwShots = startTimeBtwShots; } // Update is called once per frame void Update() { if(Vector2.Distance(transform.position, player.position) > stoppingDistance) { transform.position = Vector2.MoveTowards(transform.position, player.position, speed * Time.deltaTime); } else if(Vector2.Distance(transform.position, player.position) > stoppingDistance && Vector2.Distance(transform.position, player.position) > retreaDistance) { transform.position = this.transform.position; } else if (Vector2.Distance(transform.position, player.position) > retreaDistance) { transform.position = Vector2.MoveTowards(transform.position, player.position, -speed * Time.deltaTime); } if(timeBtwShots
At first I thought is tutorial was going to be hard to understand because I've never done c# or any other form of coding except scratch. Except for the past 3 days. But scratch actually helps me understand the else if statements and stuff but it's actually really simple to understand! Great job. I'm going to try this later.
Could you make a video on A* Pathfinding or any other method on 2D Pathfinding? There are very few Up to Date Videos on UA-cam. Thanks hope you like the suggestion.
damn after combing your previous video about top down shooting and combining it with the screen shake video and this my game has reached new heights. Thank you too much for these amazing tutorials.
If you see that your enemy is shaking or vibrating constantly, you probably just need to set the stopping and retreat distance to not be equal (if they are already). Mine were both at 5 so I just changed the stopping distance to 5.2.
Its easy, just put the "target = ......" code which is located at *start* into the *update* , so that _player.location_ is always updated, not Set. Note: to anyone who might have the same question
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Enemy : MonoBehaviour { public float speed; public float stoppingDistance; public float retreatDistance;
private float timeBtwShots; public float startTimeBtwShots; public GameObject projectile; public Transform player; // Start is called before the first frame update void Start() { player = GameObject.FindGameObjectWithTag("Player").transform; timeBtwShots = startTimeBtwShots; } // Update is called once per frame void Update() { if(Vector2.Distance(transform.position, player.position) > stoppingDistance){ transform.position = Vector2.MoveTowards(transform.position, player.position, speed * Time.deltaTime);
haha im currently doing my A-level coursework too!, trying to do an aim training game with an AI. was super optimistic for mine during the planning stage and realised how hard it is so i've had to downgrade a lot.
You are awesome bro ,the way you present your video tutorials is awesome and you even reply to almost every comment to help them it's something i really appreciate. I wish you become more successful than you can even imagine😊😊
The not moving bullet can also be usefull feature, Its like an enemy placing mines that if you step on explodes. but for the explosion it costs a diffrent coding
You can *easily* place mines in the Projectile script! public bool isAMine = false; private void Update() { if ( isAMine ) { //donut thing. } if ( !isAMine ) { MoveEnemy(); } } private void MoveEnemy() { //Move the code that used to be in the Update function here. }
Thanks a bunch :) I applied this to my current 2D platformer project and it works but I made an additional script using a 2D collider trigger that activates your follow script on trigger enter
You are awesome.your tutorial are really very easy and helpful.thankyou so much keep making your tutorial. I want a tutorial how to spawn enemies.please
Hi, This is very nice video for player followed by enemy. I would like to understand the canon rotating in direction of player's position Regards Siddesh Metrani
I have seen that lots of people wanted to have the bullet move beyond the players position. This command is used only on the EnemyBullet. public float moveSpeed = 7f; public Rigidbody2D rb; private Vector2 moveDirection; private Transform target; // Start is called before the first frame update void Start() { target = GameObject.FindGameObjectWithTag("Player").transform; moveDirection = (target.transform.position - transform.position).normalized * moveSpeed; rb.velocity = new Vector2(moveDirection.x, moveDirection.y + 0.5f); } This way every new bullet found will go towards the last player's position. You need to AddForce towards that position.
finally a tutorial i understood, subscribed, i am hoping to make a farming survival monster breeding game, if you can make any tutorial about those that would be great
Found a mistake!, Woaw! what is that man you've created a PUBLIC transform for the player gameobject and started finding it through the tag in the start method ( just blew my mind for a moment).which can be seen in the video before 5:24 and then smartly you've converted the public access specifier into a private variable in the later part of the video. and the second thing you don't need to use trasform.position = this.trasform.position; just use simply return if you want or else it's not required either. by the way your doing good job keep it up :D
I know, I saw that public and started freaking out. If the Enemy was a prefab, that slot would have been impossible to load with a Player from the Hierarchy.
Hey man, this is a really cool tutorial, but you don't mention how to get the bullet to keep going past the player's position? Could you tell me how this might be done?
@@noelmidenimstad6573 no. this will make the bullet miss the player. You need to instantly add a force to the bullet which will make it move to the point where the player stood when the bullet was instantiated.
ive been watching some of your tutorials and i just wanted to tell you, you might be my new favorite tutorial guy yes you say lots of stuff i already know BUT i like the way you teach and explain stuff its like even with you telling me something that i already knew its almost like i learned something new and interesting i just find myself enjoying your tutorials a lot so yeah thx for your tutorials im liking your character creation videos (a thing that i would like that existed 5 years ago when i was trying to reproduce one myself) and overall your artstyle is really neat (havent watched this video just wanted to post this on your most recent video) p.s. sorry for my bad english
I can confirm that it works for 3D! Here's my version (I mostly just changed Vector2's to Vector3's) using System.Collections; using System.Collections.Generic; using UnityEngine; public class ProjectileAim : MonoBehaviour { public float speed; private Transform player; private Vector3 target; public Rigidbody rb; // Start is called before the first frame update void Start() { player = GameObject.FindGameObjectWithTag("Player").transform; target = new Vector3(player.position.x, player.position.y, player.position.z ); } // Update is called once per frame void Update() { transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime); if (transform.position.x == target.x && transform.position.y == target.y && transform.position.z == target.z) { Destroy(gameObject);
Here is the full code ENEMY using System.Collections; using System.Collections.Generic; using System.Security.Cryptography; using UnityEngine; public class Enemy : MonoBehaviour { public float speed; public float stoppingDistance; public float retreatDistance; private float timeBtwShots; public float startTimeBtwShots; public GameObject projectile; public Transform player; void Start() { player = GameObject.FindGameObjectWithTag("Player").transform; timeBtwShots = startTimeBtwShots; } void Update() { if (Vector2.Distance(transform.position, player.position) > stoppingDistance) { transform.position = Vector2.MoveTowards(transform.position, player.position, speed * Time.deltaTime); } else if (Vector2.Distance(transform.position, player.position) < stoppingDistance && Vector2.Distance(transform.position, player.position) > retreatDistance) { transform.position = this.transform.position; } else if (Vector2.Distance(transform.position, player.position) < retreatDistance) { transform.position = Vector2.MoveTowards(transform.position, player.position, -speed * Time.deltaTime); } if(timeBtwShots
Hey man! How can I make the bullet to keep going straight instead of just let it die after reaching the Player coordinates??? If anyone know PLEASE let me know
How do you shoot the bullet in the direction instead of just the position? Meaning the bullet continues ahead after passing through the target position?
By having a velocity vector and adding it to the position of the projectile every frame, so that it will just carry on into the distance, but in the initial direction of the player.
Side products in the process: I made 'deadly octopus' - without timeBtwShoots = startTimeBtwShoots shoot looks like big following hand with reach; and also mine setting monster - when projectile is still.
🎯 Key Takeaways for quick navigation: 00:00 🎮 Introduction to creating a shooting enemy in Unity using C#. 00:27 🚀 The enemy moves toward the player and stops at a certain distance. Retreats if player approaches. 03:08 ⚙️ Using Vector2.Distance to check distance between player and enemy for movement logic. 05:26 🔫 Implementing shooting mechanics with adjustable time between shots and projectiles. 08:07 🛠️ Adjusting shooting frequency and adding projectile prefab to the enemy. 10:21 💥 Detecting if the projectile reaches its destination and triggering its destruction. 11:04 🔁 Using OnTriggerEnter2D to detect collision with the player and destroy the projectile. 11:45 💡 Importance of Rigidbody2D and Collider2D components for collision detection. 12:27 👍 Encouragement to ask questions and engage in the comments section. Made with HARPA AI
Please make even more Videos. I have watched the first video from you today and your code style is like mine. Short and not complicated. Already subscirbed and liked the Video. You deserve it. Can you make some Videos about 2D Character Design, i would love that. :)!!!
this is the most intense unity tutorial I have ever watched
so now i’m gonna put this PERFECT MADE RED CUBE IN MY PROJECT!!!...
I can feel his enegery trhough my screen
The nasty little square also shoots little bullet at our inoccent circle
InstaBlaster...
DUDE YOUR TUTORIALS ARE SO EASY TO LEARN! THANKS A LOT. MOST TUTORIALS ON UA-cam ARE QUITE COMPLICATED FOR ME. BUT YOUR'S IS JUST SO WELL MADE THAT EVEN SHIT LIKE ME CAN UNDERSTAND IT! THANKS SO MUCH!!!!!!
Thanks !! I'm delighted to hear that my tutorials have helped you :) ! Many, many more are coming up so stay tuned !
Blackthornprod Woooooow. I cant believe you actually noticd me! I really like your videos sir. its really helpin me out. If its ok. Can you make more tutorials about ai?
"SHIT LIKE ME" HAHAHAHA I FEEL YOU BRO
@@lhenardabraham9068 That made me LOL hard!! haha
Im more shitter than you that i couldn't understand it in first time watching 😢.
Gotta watch it a few more times and start writing the code on my computer to learn it
Spent around 2 minutes trying to figure out what the heck a "project tile" was. Haha, great tutorial man, making my first fully finished game, a mini space shooter, and this helped out alot. You and Brackys are awesome.
lmao.
ya
for anyone doing this in 3d, here is the modified script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyBehavior : MonoBehaviour
{
public float speed;
public float stoppingDistance;
public float retreatDistance;
public GameObject bullet;
public Transform player;
private float timeBtwShots;
public float startTimeBtwShots;
// Start is called before the first frame update
void Start()
{
player = GameObject.FindGameObjectWithTag("Player").transform;
timeBtwShots = startTimeBtwShots;
}
// Update is called once per frame
void Update()
{
if (Vector3.Distance(transform.position, player.position) > stoppingDistance)
{
transform.position = Vector3.MoveTowards(transform.position, player.position, speed * Time.deltaTime);
}
else if (Vector3.Distance(transform.position, player.position) < stoppingDistance && Vector3.Distance(transform.position, player.position) > retreatDistance)
{
transform.position = this.transform.position;
}
else if (Vector3.Distance(transform.position, player.position) < retreatDistance)
{
transform.position = Vector3.MoveTowards(transform.position, player.position, -speed * Time.deltaTime);
}
if (timeBtwShots
thank you
bro
legend
Oh nice. Thank you. Was just thinking about how to apply this in 3D. -b
ye just use vector 3 and add z axis everywhere
Legend!
THANK YOU. I’m currently participating in my first game jam, and I needed this
._. Pog
The clarity, simplicity and straight forward approach in the tutorial shows that you are someone who has made many games!
Thanks for sharing your knowledge.
Does this work for you? It won't let me put .transform at the end of the player find tag gameobject bit
MinecraftMadlad yes it did work for me, just check the spelling and capitalisation once. If not Let me know I’ll give the script that worked for me
@@renishadesra7336 no it's alright thanks, I just stole the full 3d designed script from that other comment lol
This tutortial is really good! I actually made a better version (in my opinion) of the movement.
public GameObject target;
float distance;
public float speed;
void Update()
{
distance = Vector3.Distance(gameObject.transform.position, target.transform.position) - 6.5f; (higher = enemy stays farther away, can be anything)
speed = distance;
transform.position = Vector2.MoveTowards(transform.position, target.transform.position, speed * Time.deltaTime);
}
This makes it so that the enemy speeds up depending on how far away the player is form the enemy.
I was simling the whole time I was watching this. It was so intense. It felt like I was watching a conspiricy theory. Amazing tutorial BTW.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemyshooting : MonoBehaviour
{
public float speed;
public float stoppingDistance;
public float retreaDistance;
private float timeBtwShots;
public float startTimeBtwShots;
public Transform player;
public GameObject projectile;
// Start is called before the first frame update
void Start()
{
player = GameObject.FindGameObjectWithTag("Player").transform;
timeBtwShots = startTimeBtwShots;
}
// Update is called once per frame
void Update()
{
if(Vector2.Distance(transform.position, player.position) > stoppingDistance)
{
transform.position = Vector2.MoveTowards(transform.position, player.position, speed * Time.deltaTime);
} else if(Vector2.Distance(transform.position, player.position) > stoppingDistance && Vector2.Distance(transform.position, player.position) > retreaDistance)
{
transform.position = this.transform.position;
}
else if (Vector2.Distance(transform.position, player.position) > retreaDistance)
{
transform.position = Vector2.MoveTowards(transform.position, player.position, -speed * Time.deltaTime);
}
if(timeBtwShots
Soooo underrated
He should pin it
@@DopEZTam check the program name
@@DopEZTam OK... Well nice videos... Which game is that in ur yt
@@DopEZTam oh ...can we play in phone?
At first I thought is tutorial was going to be hard to understand because I've never done c# or any other form of coding except scratch. Except for the past 3 days. But scratch actually helps me understand the else if statements and stuff but it's actually really simple to understand! Great job. I'm going to try this later.
Could you make a video on A* Pathfinding or any other method on 2D Pathfinding? There are very few Up to Date Videos on UA-cam.
Thanks hope you like the suggestion.
Look at brackeys tutorial
damn after combing your previous video about top down shooting and combining it with the screen shake video and this my game has reached new heights. Thank you too much for these amazing tutorials.
If you see that your enemy is shaking or vibrating constantly, you probably just need to set the stopping and retreat distance to not be equal (if they are already). Mine were both at 5 so I just changed the stopping distance to 5.2.
Dude, thk you!!!!!
Ik this is a really old comment and you probably forgot about this at this point but is there explanation for why it shakes given other numbers?
Nice but wished it showed an option of the projectile still following after it reaches the targeted position
Its easy, just put the "target = ......" code which is located at *start* into the *update* , so that _player.location_ is always updated, not Set.
Note: to anyone who might have the same question
@@dragneeladhoo6023 it didnt work
@@keremaslan1988 you could try this amd check...
public class HomingMissile : MonoBehaviour{
public Transform target;
public Rigidbody2D rigidBody;
public float angleChangingSpeed;
public float movementSpeed;
void FixedUpdate () {
Vector2 direction = (Vector2)target.position - rb.position; direction.Normalize ();
float rotateAmount = Vector3.Cross (direction, transform.up).z;
rigidBody.angularVelocity = -angleChangingSpeed * rotateAmount;
rigidBody.velocity = transform.up * movementSpeed;
}}
Hope you can make it work. It works for me.
I think you can use the rigidbody of the projectile and add force ..
I highly enjoy these videos, you and a few others are the reason why I've wanted to make video games
this video is old but thank you, you helped me whit a problem i had for 3-4 consecutive days.
Quick tip if you want to Destroy a game object after a few seconds then just specify the time by doing Destroy(gameObject, write the time here)
copy and paste code is in reply's. Watch the video though it gives good explanations.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Projectile : MonoBehaviour
{
public float speed;
private Transform player;
private Vector2 target;
void Start()
{
player = GameObject.FindGameObjectWithTag("Player").transform;
target = new Vector2(player.position.x, player.position.y);
}
// Update is called once per frame
void Update()
{
transform.position = Vector2.MoveTowards(transform.position, target, speed * Time.deltaTime);
if(transform.position.x == target.x && transform.position.y == target.y){
DestroyProjectile();
}
}
void DestroyProjectile(){
Destroy(gameObject);
}
void OnCollisionEnter2D(){
DestroyProjectile();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
public float speed;
public float stoppingDistance;
public float retreatDistance;
private float timeBtwShots;
public float startTimeBtwShots;
public GameObject projectile;
public Transform player;
// Start is called before the first frame update
void Start()
{
player = GameObject.FindGameObjectWithTag("Player").transform;
timeBtwShots = startTimeBtwShots;
}
// Update is called once per frame
void Update()
{
if(Vector2.Distance(transform.position, player.position) > stoppingDistance){
transform.position = Vector2.MoveTowards(transform.position, player.position, speed * Time.deltaTime);
} else if(Vector2.Distance(transform.position, player.position) < stoppingDistance && Vector2.Distance(transform.position, player.position) > retreatDistance){
transform.position = this.transform.position;
} else if(Vector2.Distance(transform.position, player.position) < retreatDistance){
transform.position = Vector2.MoveTowards(transform.position, player.position, -speed * Time.deltaTime);
}
if(timeBtwShots
Wow...UA-cam suggested your channel. Very cool videos so far. Keep it up mate!
Hey :) ! Thanks man that is awesome to hear ! I definitely intend to keep it up !
love your videos, you should do a 2d grappling hook tutorial
>finds no useful video, gives up on A-level coursework.
>comes back a month later and finds this.
>MightGetAnALevel.jpg
haha im currently doing my A-level coursework too!, trying to do an aim training game with an AI. was super optimistic for mine during the planning stage and realised how hard it is so i've had to downgrade a lot.
lol
I LOVE YOUR ART STYLE!!!
bruv..its just squares and circles lol
Dude, You have inspired me to continue with my indie games. Thank you so much
How is the progress?
Cool! Really nice beginner shooting game in just 12 min! Well done! 👍🤓
when I have not found an answer for a while, this person arrives and solves it in 12.54 seconds
He uses Black magic. When he was small his mother prodded him with a black thorn.
You are awesome bro ,the way you present your video tutorials is awesome and you even reply to almost every comment to help them it's something i really appreciate. I wish you become more successful than you can even imagine😊😊
The not moving bullet can also be usefull feature, Its like an enemy placing mines that if you step on explodes. but for the explosion it costs a diffrent coding
You can *easily* place mines in the Projectile script!
public bool isAMine = false;
private void Update()
{
if ( isAMine )
{
//donut thing.
}
if ( !isAMine )
{
MoveEnemy();
}
}
private void MoveEnemy()
{
//Move the code that used to be in the Update function here.
}
Sir your way of explaining is just Really really awesome 👍 love from INDIA
you are awesome dude, thanks for keeping things simple and easy to understand.
Thank you
We miss your awsome tutorials
OMG! my AI is alive!! Thank you blackthorn!
Yay! Thx for this. I implemented this in 3d and it worked just great. This video encouraged me to be creative with my code. Thx a lot.
Oh man, this is gold. Thank you for sharing!
Man I love your enthusiasm
Thanks a bunch :)
I applied this to my current 2D platformer project and it works but I made an additional script using a 2D collider trigger that activates your follow script on trigger enter
can you show me how? for some reason when i add on trigger enter it doesnt fire the shoot script..
Your vids are forever awesomely. Please never stop😊
I know its an old video but if you want to do it in 3d just change Vector2 to vector3
You are awesome.your tutorial are really very easy and helpful.thankyou so much keep making your tutorial. I want a tutorial how to spawn enemies.please
I like the figures that you've drawn
Praise UA-cam speed settings.
i use this to make turret.Thanks Noa!
@Blackthornprod Awesome Videos. For faster prototyping you can right click inside Assets and Select Create > Sprites to make basic shapes.
really easy to keep up with and actually good codes keep em coming mate!
Hi,
This is very nice video for player followed by enemy. I would like to understand the canon rotating in direction of player's position
Regards
Siddesh Metrani
When he is retreating and I lead him to a wall and they both have colliders but the enemy clips through the wall, other than that great tutorial!
Love your tutorials! I can easily adapt the code into my game!
you are incredibly good teacher
I have seen that lots of people wanted to have the bullet move beyond the players position.
This command is used only on the EnemyBullet.
public float moveSpeed = 7f;
public Rigidbody2D rb;
private Vector2 moveDirection;
private Transform target;
// Start is called before the first frame update
void Start()
{
target = GameObject.FindGameObjectWithTag("Player").transform;
moveDirection = (target.transform.position - transform.position).normalized * moveSpeed;
rb.velocity = new Vector2(moveDirection.x, moveDirection.y + 0.5f);
}
This way every new bullet found will go towards the last player's position.
You need to AddForce towards that position.
the tutorial is still up to date right?
Thx!
Thank you so much for these.
Awesome Tutorial. Thanks for this. :)
finally a tutorial i understood, subscribed, i am hoping to make a farming survival monster breeding game, if you can make any tutorial about those that would be great
Awesome tutorial, dude! Thanks!
Very good tutorial. And i've seen a lot of them. Thank you!
Thanks tomiselma :) !!
Great videos man, you deserved my like.
great video 👏
can you do special 👌 tuto about particular effect 😊 (add (specification place) change ...)
Exactly what I was looking for. Thanks.
I have a question. How to make enemy AI same as enemy in the bomberman game. thanks a lot
you should continue doing tutorials! loved it
This is so helpful for game jams!
Thanks! is very very cool, i search this code for all's pages!
Loved the video you explain well!
nice tutorial, ill make this a base for my work. thank you!
Awesome Tutorial
In the beginning, it sounds like you are talking to Conan who are about to go for a epic quest or something, easy now xD
Thanks man your frickin awesome and dont deny it
Found a mistake!,
Woaw! what is that man you've created a PUBLIC transform for the player gameobject and started finding it through the tag in the start method ( just blew my mind for a moment).which can be seen in the video before 5:24 and then smartly you've converted the public access specifier into a private variable in the later part of the video.
and the second thing you don't need to use trasform.position = this.trasform.position; just use simply return if you want or else it's not required either.
by the way your doing good job keep it up :D
I know, I saw that public and started freaking out. If the Enemy was a prefab, that slot would have been impossible to load with a Player from the Hierarchy.
thank you I had some problems but I fixed it!
bro your tutorials are awesome i am also 17 and i want to get into game dovelopment for that your tutorials are very helpful for me
you are great small videos and neat explanation thanks
Very Very Very good... Thank you.. great video
Hey man, this is a really cool tutorial, but you don't mention how to get the bullet to keep going past the player's position? Could you tell me how this might be done?
@@noelmidenimstad6573 no. this will make the bullet miss the player. You need to instantly add a force to the bullet which will make it move to the point where the player stood when the bullet was instantiated.
@@bungercolumbus help how do i do this
ive been watching some of your tutorials and i just wanted to tell you, you might be my new favorite tutorial guy yes you say lots of stuff i already know BUT i like the way you teach and explain stuff its like even with you telling me something that i already knew its almost like i learned something new and interesting i just find myself enjoying your tutorials a lot so yeah thx for your tutorials im liking your character creation videos (a thing that i would like that existed 5 years ago when i was trying to reproduce one myself) and overall your artstyle is really neat (havent watched this video just wanted to post this on your most recent video)
p.s. sorry for my bad english
btw hyped to play fire of belief the game looks so cool it makes me remember of binding of isaac
That's so appreciated and motivating :) !! Thanks !
I can confirm that it works for 3D! Here's my version (I mostly just changed Vector2's to Vector3's)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ProjectileAim : MonoBehaviour
{
public float speed;
private Transform player;
private Vector3 target;
public Rigidbody rb;
// Start is called before the first frame update
void Start()
{
player = GameObject.FindGameObjectWithTag("Player").transform;
target = new Vector3(player.position.x, player.position.y, player.position.z );
}
// Update is called once per frame
void Update()
{
transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
if (transform.position.x == target.x && transform.position.y == target.y && transform.position.z == target.z)
{
Destroy(gameObject);
}
}
void OnCollisionEnter(Collision collision)
{
if (collision.collider.tag != "Obstacle" || collision.collider.tag == "null")
{
Destroy(gameObject);
}
}
IEnumerator DestroySoon()
{
yield return new WaitForSeconds(2);
Destroy(gameObject);
}
}
Thanks so much! However my bullets are shoot straight down, Do you know how to fix this?
Also do I need the Rigidbody part?
@@masoncrowe Hmm... did you select the correct target?
use this to flip the sprite of the enemy
void Start()
{
rb = GetComponent();
}
void FixedUpdate()
{
moveInput = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
if (facingRight == false && moveInput > 0)
{
Flip();
}
else if (facingRight == true && moveInput < 0)
{
Flip();
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}
make sure to erase the Void Start or pste the code
Which variables did you create before void start?
Could you please make a complete series on top down 3d shooter. Please
Nice Tutorial dude
Great video!
Thanks for tutorial!
Here is the full code
ENEMY
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using UnityEngine;
public class Enemy : MonoBehaviour
{
public float speed;
public float stoppingDistance;
public float retreatDistance;
private float timeBtwShots;
public float startTimeBtwShots;
public GameObject projectile;
public Transform player;
void Start()
{
player = GameObject.FindGameObjectWithTag("Player").transform;
timeBtwShots = startTimeBtwShots;
}
void Update()
{
if (Vector2.Distance(transform.position, player.position) > stoppingDistance)
{
transform.position = Vector2.MoveTowards(transform.position, player.position, speed * Time.deltaTime);
}
else if (Vector2.Distance(transform.position, player.position) < stoppingDistance && Vector2.Distance(transform.position, player.position) > retreatDistance)
{
transform.position = this.transform.position;
}
else if (Vector2.Distance(transform.position, player.position) < retreatDistance)
{
transform.position = Vector2.MoveTowards(transform.position, player.position, -speed * Time.deltaTime);
}
if(timeBtwShots
Thanks!
Hey man! How can I make the bullet to keep going straight instead of just let it die after reaching the Player coordinates??? If anyone know PLEASE let me know
behold! I show you all! The HAPPIEST coder that has ever walked (or sat on his chair coding) over the face of this planet!
That intro gave me chills
Soo good video dude!
How do you shoot the bullet in the direction instead of just the position? Meaning the bullet continues ahead after passing through the target position?
I develop 3D game, it's Vector3.forward. I think it'll be Vector2.forward ?
By having a velocity vector and adding it to the position of the projectile every frame, so that it will just carry on into the distance, but in the initial direction of the player.
@@foreversleepy4379 Any Idea on how to do this with the code we have here?
ultra great n00b tuts. u rule.
I'm gonna try to use this for an escort mission kind of code, i think it will work well when i remove the shooting part. Thanks!
Side products in the process: I made 'deadly octopus' - without timeBtwShoots = startTimeBtwShoots shoot looks like big following hand with reach; and also mine setting monster - when projectile is still.
So help full. Thank you
Well done! Keep it up!
You never dissapoint me :D
wow ..muito bom ...thanks
This is amazing code, thanks.
🎯 Key Takeaways for quick navigation:
00:00 🎮 Introduction to creating a shooting enemy in Unity using C#.
00:27 🚀 The enemy moves toward the player and stops at a certain distance. Retreats if player approaches.
03:08 ⚙️ Using Vector2.Distance to check distance between player and enemy for movement logic.
05:26 🔫 Implementing shooting mechanics with adjustable time between shots and projectiles.
08:07 🛠️ Adjusting shooting frequency and adding projectile prefab to the enemy.
10:21 💥 Detecting if the projectile reaches its destination and triggering its destruction.
11:04 🔁 Using OnTriggerEnter2D to detect collision with the player and destroy the projectile.
11:45 💡 Importance of Rigidbody2D and Collider2D components for collision detection.
12:27 👍 Encouragement to ask questions and engage in the comments section.
Made with HARPA AI
This is soo great!
this is really easy thank you!
dang dude, FIRE TUTORIALS!!1
Please make even more Videos. I have watched the first video from you today and your code style is like mine. Short and not complicated. Already subscirbed and liked the Video. You deserve it.
Can you make some Videos about 2D Character Design, i would love that. :)!!!
Wow
That was really cool
Wow that was really cool
Gooood man!
Very nice
Thank you very much