How to create basic AI (that follows the player if spotted) in 3D?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Cobra!
:warning: Old Version Published before Godot 3 was released.

Just to clarify, as I’ve seen this confusion in similar questions, I am not looking for navmeshes or pathfinding right now. For now, I just want to create a simple AI that follows the player if the player hits it’s raycast, that’s all.

The problem is figuring out how to make the enemy rotate to face the player and move forward in that direction… I haven’t got a clue on where to begin…

I have managed to make the AI move in the one direction when it spots the player, but that’s about it.

I’ve tried look_at, but that doesn’t seem to actually make the object turn… =/

Here’s what I have so far:

if targetRay.is_colliding():
			if targetRay.get_collider().is_in_group("Player"):
				move(FollowTarget(targetRay.get_collider(), delta))

func FollowTarget(test, delta):
	var velocity = Vector3()
	if get_translation().distance_to(test.get_translation()) < 100:
		currentDirection = currentDirection.linear_interpolate(minusY(-test.get_translation()), clamp(turnSpeed * delta, 0, 1))
		look_at(minusY(-test.get_translation()), Vector3(0, 1, 0))
		if abs(velocity.z) < tapSpeed:
			velocity.z += acceleration * delta
			nextAnim = "Rinnin"
	return velocity

How do I make it turn and move according to it’s direction?

Check this to see how to make smooth rotations and movement on 3D.

http://codetuto.com/2016/01/godot-engine-movement-and-rotation-basics/

eons | 2016-12-22 04:32

:bust_in_silhouette: Reply From: Gokudomatic2

You might be interested in the component I’m preparing to release in the Asset Library:

I use a state machine to switch between idling, walking and chasing modes. And for the player detection, I calculate the angle between the mob front vector and the player on the horizontal plane (meaning the mob see in 2D, and height is not considered). I also implemented a mob-vs-mob system like in Doom1&2, but I’ll release it more like an additional example because it’s already a bit too specific AI.
For following the player, my component includes a waypoint system, mostly for fixing navmesh pitfalls but which works also without any navmesh.

The only restriction is, this component is made for mobs who walk on a floor. Everything is thought with the axiom that Y axis is the vertical axis (and Z is the front axis). For a spaceship in a 0 gravity environment and rotation in every axis, like the descent games, this component would not fit.