Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Unity Artificial Intelligence Programming

You're reading from   Unity Artificial Intelligence Programming Add powerful, believable, and fun AI entities in your game with the power of Unity 2018!

Arrow left icon
Product type Paperback
Published in Nov 2018
Publisher Packt
ISBN-13 9781789533910
Length 246 pages
Edition 4th Edition
Languages
Tools
Arrow right icon
Authors (3):
Arrow left icon
Dr. Davide Aversa Dr. Davide Aversa
Author Profile Icon Dr. Davide Aversa
Dr. Davide Aversa
Clifford Peters Clifford Peters
Author Profile Icon Clifford Peters
Clifford Peters
Aung Sithu Kyaw Aung Sithu Kyaw
Author Profile Icon Aung Sithu Kyaw
Aung Sithu Kyaw
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Introduction to AI FREE CHAPTER 2. Finite State Machines 3. Randomness and Probability 4. Implementing Sensors 5. Flocking 6. Path-Following and Steering Behaviors 7. A* Pathfinding 8. Navigation Mesh 9. Behavior Trees 10. Machine Learning in Unity 11. Putting It All Together 12. Other Books You May Enjoy

The player's tank and the aspect class

The Target object is a simple sphere object with the mesh render disabled. We have also created a point light and made it a child of our Target object. Make sure that the light is centered, or it will not be very helpful.

Look at the following code in the Target.cs file:

using UnityEngine; 
 
public class Target : MonoBehaviour { 
 
    void Update ()
{
int button = 0;

//Get the point of the hit position when the mouse is being clicked
if(Input.GetMouseButtonDown(button))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(ray.origin, ray.direction, out hitInfo))
{
Vector3 targetPosition = hitInfo.point;
transform.position = targetPosition;
}
}
} }

Attach this...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime