I will see if I can add a way to ignore entities in the next update.
Just any entities with a “ignore tag” maybe? but also can you maybe just tell me what code to add since I already added ai to the project I am working on
Yes, it will be something like that. I can’t tell you what to do exactly as I first need to check and test. I expect you can do something similar as I describe in the post below.
Version 1.3 is released!
In this release a lot is changed and maybe it need to be fine tuned based on your feedback. Special thanks to @Brent_Reddick for his feedback to be able to make the right decisions and also for sharing his project to test the AI.
-
Attributes
The available attributes are easy to use and should allow the AI to work in most games.- View Distance
The distance of a target is being visible.
A view distance of zero means the enemy can’t see targets. - Hear Distance
The distance of a target withAudible
tag is being audible.
A hear distance of zero means the enemy can’t hear targets. - Patrol Range
The range of patrolling based on the origin.
A patrol range of zero means the enemy will not patrol arround. - Combat Range
The range of combat based on the equipment.
A combat range of zero means the enemy will not attack. - Enemy Speed
The default speed for moving and rotation.
The actual speed of the enemy is controlled in the states. - Sensor Length
The length of sensors to detect obstacles.
The sensor length should depend on the scale and environment. - Sensor Height
The height of sensors to detect obstacles.
The sensor height should depend on the scale and environment. - Show sensors
Ability to show the sensors for debugging.
- View Distance
-
Update Target
This functions find the closest target for the AI based on the targets in game. You can add a new target at runtime usingthis.enemyTargets.push(target)
or remove a target usingthis.enemyTargets.delete(target)
. -
Update Movement
This function moves and rotates the enemy in the direction of the destination. It avoid obstacles using the sensors. (Sinds there is no pathfinding, there are some limitations why not always the desired result can be achieved). -
Update Animation
This function animates your charachter based on a couple of conditions. You only have to assign the animations to the anim component and be sure it is enabled. By default no animations are used. -
Update State
This function only execute the current state. All other state related code is now incorporated in the specific states. -
Enemy States
Currently the AI has three states (patrol, chase and combat). Every state should have the information about what the AI has to do in the current state and when the AI has to change to another state. -
Other functions
There are a couple of other functions at the bottom of the script. One of them is the attack function, that create and fire a new bullet, when the enemy is in combat. You are free to study and change the functions.
Please note that the functions are all capitalized now, to make the script easier to read. The bullet entity is removed from the character and a template entity is used instead. The UI of the characters is removed, because it turned out that this was not used in users’ projects. I added the abiltity to ignore obstacles with an Ignore
tag.
https://playcanvas.com/project/870482/overview/basic-enemy-ai
Cool!
Hey @Albertos I doubt you will use this, this is not a suggestion or anything, just something you might wanna check out for the ai Released: Hephauestus Grid Pathfinding
I just saw what the path finding does, and it kinda blew my mind, if you were somehow able to add something similar this to the ai without making it too complicated, the enemy ai would be FLAWLESS, I bet it is just wishful thinking, but if it could be added to the enemyDestination stuff. I am not saying the raycasts are not good enough, they are, but there is always room for improvement.
This is no longer available and was a paid solution that I couldn’t use in a public project.
I created this project because of the lack of pathfinding in PlayCanvas, not because I like the raycasts that much.
As soon as there is a better alternative, I’m happy to use it.
So I can’t even buy it anymore?
Unfortunately, that’s correct.
I am trying to get the ai to go through the door, I tagged them all with ignore, (I’m using templates, it makes things easier, thanks) but even then he won’t could you help me out? (This is a new project btw) I already know how I plan to make him “open” doors but first I need him to go through it. Thanks in advanced
Also going back to the specific turn lengths, maybe not lengths but positions, my character is very wide so his arms cut into objects and stuff.
Be aware it should be Ignore
instead of ignore
.
What I have seen in your previous test project is that it works perfectly fine. It are just some edge cases that I cannot prevent. Making the side sensors longer will affect the AI negatively in other cases.
By the way, your doors are also a reason not the make the sensor length too long. It will faster detect the walls around the door and let the AI avoid.
Got it, thanks
I miss turning speed, because the ai will get stuck in the spawn point (the super tiny room)
Yes, this is also an edge case where in front and behind the AI is an obstacle. It also tells me your door is currently not ignored.
It is ignored, but the space is so small idk, is there a way to make the ai avoid that room completely even if the player opens the door.