I used most of the code up until around the 3:45 mark, and then found that I didn’t need the information in the rest of the video.
What I would like help with is making it so the enemy AI can be dodged, causing the NPC to have to slow down and reverse directions before it can continue pursuing the player. As of right now, the enemy follows the player at a constant speed, always moving in the direction of the player. My thinking is that it could be done with some type of interpolation, but I am a beginner programmer who has no idea what he is doing and therefore could very well be wrong.
How should I approach implementing this feature? Are there any useful tutorials or other resources that could help me out? Any and all help is appreciated!
If you specifically want the enemy to delay when the player is directly outside of its vision - you could probably keep track of the player and enemy position as a variable within the enemy script, inside its physics process function.
Keep comparing both of their positions - once the player’s position is roughly behind the enemy:
return.
Return stops running the rest of the block of code.
There’s also an asset called VisionCone3D on the asset library. You could use that I imagine and not need to track the players position using variables.
If nothing’s working straight away, you could “cheese” it by having an area3d directly attached to the enemy’s back. Adjust the size to your liking and just trigger a delay in the follow logic when the player enters it.
Although this probably isn’t the correct way to do it
Thanks for the response! I’m confused by what you’re saying. Perhaps I didn’t describe my issue correctly. I am trying to create an enemy AI that acts more like a RigidBody3D, in that it can be acted on by outside forces (other objects within the scene) and act out forces on said objects as well.
I also want the enemy to have to speed up in order to catch the player, and slow down and reverse if it is heading in the wrong direction, kind of like a vehicle would (Although I’m not sure a VehicleBody3D would be the solution, that is just the best way I can describe it). Does your description match what I am trying to produce? If so, would you mind explaining further?
Forgive me, I am new to all of this, and a lot of these terms and phrases seem foreign to me :).
This is a great way of doing it without overcomplicating things. If you add acceleration, deceleration / friction - the AI will naturally delay the way you want it to