Cheetah 3d in unity
![cheetah 3d in unity cheetah 3d in unity](https://burningthumb.com/wp-content/uploads/Screen-Shot-2021-01-10-at-12.17.33-PM-1024x650.png)
Level design is going well it’s a much slower process than I anticipated though! Over time, playing around with the raycast/linecast systems more, I began to realize that my conditional structures were causing a lot of the weirdness I was seeing. Raycasts provide more information and control than a linecast but ultimately the easiest method turned out to be checking whether the linecast hits the player or something else first. Both provide information on the first game object they hit which has a collider component on it. Linecasts and raycasts are built into Unity a linecast is between two points, and a raycast is emit from a single point. While eventually I used a linecast, I spent a lot of time trying to get a raycast to work. It was this third element that caused a lot of trouble. And thirdly, there must be no solid object blocking the player from the enemy. Secondly, the player must not be too far away from the enemy. First, the player must be within a certain angle of the front of the enemy (in it’s cone of vision). To see the player, the AI requires three things.
![cheetah 3d in unity cheetah 3d in unity](https://media.sketchfab.com/models/91154a3b81ea45ec8912c0a7bde75ec5/thumbnails/76f6259b282f4358b286cc3bfc0bf417/0a3a8b427327408e88ac15332354f44f.jpeg)
The first, and the one we’re interested in here, is whether the enemy can see the player or not. Currently there are only two tests however. The idea is that the enemy checks for the strictest test, then the second strictest, and so on. Some of them, such as distance to player, are somewhat self explanatory.Īfter the variables (and two debug prints to the console) comes the actual code.
![cheetah 3d in unity cheetah 3d in unity](https://img.itch.zone/aW1nLzE2ODMxNTIucG5n/original/Sbg5LJ.png)
In the beginning, I define the variables I’ll need. There’s a fair amount of Unity mumbo jumbo in there.
![cheetah 3d in unity cheetah 3d in unity](https://siteurban309.weebly.com/uploads/1/2/6/4/126454818/845937878.jpg)
Var playerAngle = Vector3.Angle(directionToPlayer, transform.forward) Var targetAngle = Vector3.Angle(directionToTarget, transform.forward) //for vision
#CHEETAH 3D IN UNITY CODE#
This is the code in the enemy AI script that tests whether the enemy can see the player or not.ĭirectionToTarget = – transform.position ĭirectionToPlayer = – transform.position ĭistanceToPlayer = Vector3.Distance(transform.position, ) Other minor tweaks abound, too, including tighter movement for the enemy more suited to indoor environments. It should just grab the nearest waypoint that leads to where it lost sight of the player, and travel along that path, but oftentimes it grabs an impractical waypoint as its target (at one point I was crashing the game with a possibly infinite loop. I’m having some problems keeping the AI from getting confused if it sees the player, chases him, and then loses sight. It simply checks what path the player is on, then, if the AI is not on that path, can check the nearest connected path, until it figures out a route and begins traveling it.
#CHEETAH 3D IN UNITY HOW TO#
If the AI is alerted to the player’s presence by an alarm (something which, in this system, would be extremely easy to implement), the AI can figure out how to get to the player from even a great distance away. The prime reason is that it allows the AI to reach a specific destination much more quickly. Waypoints are split into paths for several reasons. Each waypoint stores information about itself, such as what path it is in, its position in that path, and what paths are connected to that waypoint. Waypoints are grouped into ‘paths,’ marked by color. They show up in the editor as cubes of various colors, but they are invisible in the actual game. Scattered throughout the level are waypoints. The textures are slightly random and all very free. What you see here is a small section of the level I’m using to test navigation. That’s alright when the AI has a large field of vision, or is near the player, but in an indoor environment with multiple paths and many barriers, that just doesn’t cut it. The waypoint system I had before simply said ‘if you can’t find the player, just loop around these waypoints until you do”. I’ve rehauled the entire waypoint system to allow more intellegent navigation of an indoor environment.