# Can give any example of 3D raycast Enemy moving or following Player to Collision?

Attention Topic was automatically imported from the old Question2Answer platform.
Old Version Published before Godot 3 was released.

I need any help or other idea for 3D enemy search Player till collision

thank you

I dont know what a “3D Raycast Enemy” is but to follow something is the classic TranslationA-TranslationB to get the distance.

For smooth approach you can make a linear interpolation of the positions, advanced following may require to design a steering behaviour (like pursuit).

For basics of movement, this tutorial covers many things in godot:
http://codetuto.com/2016/01/godot-engine-movement-and-rotation-basics/

If you are interested in the advanced (but simple) techniques you can read about steering behaviours here (is generic):
https://gamedevelopment.tutsplus.com/series/understanding-steering-behaviors–gamedev-12732

The enemy is a script that knows the whole scene. Thus you can calculate player.translation-self.translation to have a vector that points directly to the player with the distance between them. No need for a raycast for that. Also, you can do this with Transforms and their method Looking_at.
But I guess it’s not what you want, right? I think you’re not only asking for a raycast but for a whole AI that can move and detect collisions.

look please enemy not on the world yet.when i walking in same area of map enemy is add with add_child but how enemy will get my position for rotate to my direction and how he will detect my distance is not with RayCast?

thanks

linuxfree | 2016-10-17 17:56

He’ll get your position with a get_node of your player’s node. Since his node and the player’s node must be on the scene, then a get_node of the player from this scene will give you the possibility to get then the global transform of the player. And since you can do that within the script of the enemy, you simply need to substract the translation vector of the enemy from the translation vector of the player, and the resulting vector gives you the direction to the player.
Excuse me to ask, but I’ve the feeling you’re uneasy with vector maths. If it’s the case, you should maybe check godot’s doc, chapter about vectors.

Gokudomatic2 | 2016-10-17 18:05