# Creating my own AI Bots

**URL:** <https://forums.unrealengine.com/t/creating-my-own-ai-bots/1886>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [April 5, 2014, 2:58am UTC](https://forums.unrealengine.com/t/creating-my-own-ai-bots/1886 "2014-04-05T02:58:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_a1f8501a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a1f8501a](https://forums.unrealengine.com/u/anonymous_user_a1f8501a)\
**Post date:** [April 5, 2014, 2:58am UTC](https://forums.unrealengine.com/t/creating-my-own-ai-bots/1886/1 "2014-04-05T02:58:13Z")

</div>

So first, I’ve gotten too use to Unity where the code was simply put into little self contained scripts, such as this little guy done in C#

```auto

using UnityEngine;
using System.Collections;

 class EnemyAI : MonoBehaviour {

	private Transform target;
	 int moveSpeed;
	 int rotationSpeed;
	 int maxDistance;

	private Transform myTransform;

	void Awake() {
		myTransform = transform;
	}

	// Use this for initialization
	void Start () {
		GameObject go = GameObject.FindGameObjectWithTag ("Player");
		target = go.transform;
		maxDistance = 2;
	}
	
	// Update is called once per frame
	void Update () {
		//Looks at target
		myTransform.rotation = Quaternion.Slerp (myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);

		if (Vector3.Distance (target.position, myTransform.position) > maxDistance) {
			//Move towards target
			myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
		}
	}
}

```

Now I’m actually attempting in translating that simple AI code into UE4, which is actually quite a challenge I’m facing. Though it would be a good base to actually start programming but I’m finding it a bit harder to get comfortable then I was hoping it would be. I’ve ran through the documentation and such and I have been trying to dissect the Bot code from the Shooter Game sample that they have. What I’m really facing in trying to accomplish this little task in the wrapper and skin of the UE4 coding structure. I was mainly hoping if someone could help explain the little nuances of coding in the program, or had time to explain a few key things in when I’m attempting to write my own code for UE4. I have to get out of the mindset of programming for Unity!

Any tips, hints, suggestions or pointers?

---

<div class="post-metadata">

**Author:** ![Agentleo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Agentleo](https://forums.unrealengine.com/u/Agentleo)\
**Post date:** [April 5, 2014, 4:08am UTC](https://forums.unrealengine.com/t/creating-my-own-ai-bots/1886/2 "2014-04-05T04:08:16Z")

</div>

I recommend you look into Actor class as a starting point.

Below is a link to a wiki article that was started to help those coming from Unity that may not be familiar with C++ and also talks about equivalent functions between the two engines.

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f54268a3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f54268a3](https://forums.unrealengine.com/u/anonymous_user_f54268a3)\
**Post date:** [April 5, 2014, 4:26am UTC](https://forums.unrealengine.com/t/creating-my-own-ai-bots/1886/3 "2014-04-05T04:26:05Z")

</div>

This stuff would probably go in a class extending AIController.

Your variables go in the header. the .h file.

I don’t think you need the Awake function or the transform it’s referencing. Get the ControlledPawn and the Location.

The code your doing in Start would be in BeginPlay:  
[https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/GameFramework/AActor/BeginPlay/index.html](https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/GameFramework/AActor/BeginPlay/index.html)

The things in your Update function go into Tick.  
[https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/GameFramework/AActor/TickActor/index.html](https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/GameFramework/AActor/TickActor/index.html)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a1f8501a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a1f8501a](https://forums.unrealengine.com/u/anonymous_user_a1f8501a)\
**Post date:** [April 5, 2014, 4:41pm UTC](https://forums.unrealengine.com/t/creating-my-own-ai-bots/1886/4 "2014-04-05T16:41:22Z")

</div>

Ah, those links are really helpful. I hadn’t programmed in C++ for a bit close to a year so the guidance is really helpful.

> [@](#):
>
> I recommend you look into Actor class as a starting point.
> 
> Below is a link to a wiki article that was started to help those coming from Unity that may not be familiar with C++ and also talks about equivalent functions between the two engines.
> 
> [A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums](https://wiki.unrealengine.com/Unity3...nreal_Engine_4)

Very helpful link! Thanks a ton for that, it’s actually clearing up a bunch of transitional confusion I was having.

> [@](#):
>
> This stuff would probably go in a class extending AIController.
> 
> Your variables go in the header. the .h file.
> 
> I don’t think you need the Awake function or the transform it’s referencing. Get the ControlledPawn and the Location.
> 
> The code your doing in Start would be in BeginPlay:  
> [https://docs.unrealengine.com/latest...lay/index.html](https://docs.unrealengine.com/latest...lay/index.html)
> 
> The things in your Update function go into Tick.  
> [https://docs.unrealengine.com/latest...tor/index.html](https://docs.unrealengine.com/latest...tor/index.html)

Again, very helpful. The direction is much appreciated and the breakdown of where each part of the code would go is going to be very useful for other codding projects.
