I know you posted this a long time ago, but what I usually do is model the area I want the AI to be searching within in Blender, add it as a separate mesh collider on the main AI GameObject, then use OnTriggerStay() for checking for the player and whatever. You could also just draw/otherwise make a 2D version of such a collider, probably in an art program like Photoshop, or simply editing a polygonal collider 2D.
@@BitPlayYT Ik this is an old comment, but you can detect it with the way provided above, and then use Raycast to check if the sight is actually clear. Cheers.
Get the angle between the two vectors, the enemy's head and players head, check if it's less than a specified angle, such as 50, then raycast from the enemy's head to the players head, if it hits the players head you know hes been spotted, and then you can do the spotted action lol.
I can't see the line , even after not adding the collider to enemy . so please tell how to solve it , because i am a beginner and don't know a lot about it
I do have to admit that your tutorials are really awesome, helped me a lot in my project. Thanks for making these awesome videos and hope you can make further more videos.
i dont get my line to make circles i just stands still and when in the system it hit something it teleports to the location of the player and stops and does not conitiue
Hey blackthornprod! i really love ur videos but unfortunately this time i cant see proper results in the AI. I am actually starting to learn the basics of AI. And please help me i will give u the enemy code: using System.Collections; using System.Collections.Generic; using UnityEngine; public class Enemy : MonoBehaviour { public float roatationSpeed; public float distance; void Start() { Physics2D.queriesStartInColliders = false; } // Update is called once per frame void Update () { transform.Rotate(Vector3.forward * roatationSpeed * Time.deltaTime); RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, transform.right, distance); if (hitInfo.collider != null) { Debug.DrawLine (transform.position, hitInfo.point, Color.red); } else { Debug.DrawLine(transform.position, transform.position + transform.right * distance, Color.green); } } } I cant get the ray color on Unity please help me :(
pls help how to rotate raycast, i mean in angle for example: RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, ("here insert angle"), viewDistance);
Great video again~! Thank so much~ Noa~! I have one question about previous videos about character moving, 1. Beside using navigation agent, there are people using addforce/ moveposition/ velocity to move an player/objects, how do we decide to apply any of these methods to our player/objects? Also, I had followed your 3d AI Click-to-move navigation tutorial, and I am able to do simple interaction between player and objects, such as chat dialog, destroy objects. However, how should I imply slightly advanced interaction, such as sitting on/leaving a chair, or lift an objects and carry around.
Hey and thanks :) ! For more complex interactions simply use various functions. For example if you get near a chair you may need to press SPACE and your character will do a sitting animation (the chair could have a script that handles that). As for nav mesh agent, it can't really be replaced by addForce/movePosition... since it's a great method for pathfinding, in other words reaching a destination the fastest way possible while dodging obstacles :) ! Hope this helps ! Stay tuned and thanks again for the support !
I'd like to make it so that when enemy's raycast hits player it triggers my follow player script and when player is dead it returns to it's previous behaviour.... But i have no idea how to do this.
Can you help me so that the Line of sight is wider than the line you made Plz help but still a really good tutorial, keep making these things(from 2020)
Great video :D But when i try to do the same in 3D, the line 19, i change RaycastHit2D for RaycastHit and Physics2D for Physics, i have an error : "cannot implicity convert type 'bool' to 'UnityEngine.RaycastHit' " :(
Le monde de Léah MacBunny Yeah, it changes from 2d to 3D. If anyone’s having trouble with this, change the line from “RaycastHit2D hitInfo = blah blah” to “ “RaycastHit hitInfo; if(Physics.Raycast(transform.position, transform.right, out hitInfo, distance)) { //rest of code }”
M new to unity ,I really like your vdo Noa, really appreciate it, just could u let me know where can I find d code of blue (player) movement,please reply it will b greatfull
If I write 'Vector3.right' instead of 'transform.right' in the below line, it does not detect the object collisions. Can you please tell me what is the reason behind that? RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, transform.right, distance);
Always remember to repent of your sins (sin is transgression of YAHUAH’S LAW: Genesis, Exodus, Leviticus, Numbers, & Deuteronomy) And Have Belief On YAHUSHA HAMASHYACH. HE Died and Rose Again On The Third Day So that you can be forgiven of your sins! HE Loves you! Come to HIM!🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂