0 votes

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?

in Engine by (169 points)
edited by

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

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

1 Answer

0 votes

You might be interested in the component I'm preparing to release in the Asset Library:
https://github.com/gokudomatic/eco-fps-walker

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.

by (698 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.