Ambiera ForumDiscussions, Help and Support. |
|
| [ 1 2 ] Page 2 of 2 |
|
|||||
|
and that is all vector math... |
||||
|
Would this work? I asked ChatGPT... // NPC Assailant Object function Assailant(npcPosition, playerPosition, fieldOfView, maxSpeed) { this.position = npcPosition; this.playerPosition = playerPosition; this.fieldOfView = fieldOfView; // Angle of sight (in degrees) this.maxSpeed = maxSpeed; // Maximum movement speed (units per tick) this.state = 'patrolling'; // Can be 'chasing', 'predicting', or 'patrolling' // Basic movement methods this.moveTo = function(targetPosition) { let dx = targetPosition.x - this.position.x; let dy = targetPosition.y - this.position.y; let distance = Math.sqrt(dx * dx + dy * dy); // Normalize direction let direction = { x: dx / distance, y: dy / distance }; // Move NPC towards the target with max speed this.position.x += direction.x * this.maxSpeed; this.position.y += direction.y * this.maxSpeed; }; // Detect if the player is in the field of view this.isPlayerInSight = function() { // Simple line-of-sight detection (replace with raycasting if necessary) let dx = this.playerPosition.x - this.position.x; let dy = this.playerPosition.y - this.position.y; let angleToPlayer = Math.atan2(dy, dx) * 180 / Math.PI; let angleDifference = Math.abs(angleToPlayer); // Get absolute angle difference return angleDifference <= this.fieldOfView / 2; }; // Predict the player's movement and adjust NPC movement this.predictPlayerMovement = function() { // Simple prediction: move towards a point slightly ahead of the player’s current position let predictedX = this.playerPosition.x + Math.random() * 50; // Add some randomness for unpredictability let predictedY = this.playerPosition.y + Math.random() * 50; return { x: predictedX, y: predictedY }; }; // Main update function called every game tick this.update = function() { // Check if player is in sight if (this.isPlayerInSight()) { this.state = 'chasing'; // If player is in sight, chase the player this.moveTo(this.playerPosition); } else { this.state = 'predicting'; // If player is out of sight, predict their movement let predictedPosition = this.predictPlayerMovement(); this.moveTo(predictedPosition); } // Optionally, add some debug logging console.log(`NPC position: (${this.position.x}, ${this.position.y}), State: ${this.state}`); }; } // Example usage: let npc = new Assailant({ x: 100, y: 100 }, { x: 200, y: 200 }, 45, 2); // FOV 45 degrees, max speed 2 units per tick setInterval(function() { npc.update(); // Update NPC behavior every tick (e.g., 60 ticks per second) }, 1000 / 60); // 60 FPS (adjust as needed) |
||||
|
not as it is. it needs to be made to work with cc. for example: replace setInterval() with ccbRegisterOnFrameEvent(). if you need help with it, start a dedicated post for it instead of hijacking an old post. |
||||
|
this can be made to work with many modifications (simpler is to make new) but its probably not the assain script that you are looking for - because its kinda basic. i have tryed chat gpt and it can make actually pretty good scripts if you know how to direct it (by knowing scripting its easy ..else not so easy) depends how you ask from chatbot it gives you better results.. include words javascript and coppercube in it - current output seems has no idea about coppercube.. |
||||
|
Luposian, I heard about chatgpt, but in most part of posts in forum, the people say the chatgpt is not much usefull to use for somethings like coppercube script (at last wet). You problaby have two options in you line of script development; first is try to learn javascript version used in coppercube and study the coppercube api javascript documentation, the second is make what I did ask for help to someone who understand or understand more than you of coppercube scripts and extensions. I will very sincere with you; chatgpt is one very usefull tool but for programming, this kind of tool only be usefull with you understand programming, because you will need not to only guide the Ai, but fix and adapt parts of code generated for your personal use. Problaby for what you want to make, you can be make using the coppercube in built extensions or with comunity extension (or both) and some work, explain more about what you want and bring one example for reference. The sven, just in case have some amazing AI extensions systems, give one look to them too. I hope I had helped you Thanks the attention |
||||
|
It would be a lot easier if someone who KNOWS how to construct NPC AI routines in CopperCube/Javascript could do this. And I'd be glad to pay for it. I'm not a programmer. I'm not an artist. I'm not an animator. I'm not a voice actor. Hence why I pay for people to do things I cannot. I have access to money. That's my only leverage. If people want to help me out for free, that's their perogative (or maybe necessity). I'll be grateful, but I don't expect/request free help. I've gotten my game as far as I currently have, because of others. Paid and free help, combined, to get the game where it is, today. "Programming Logic" is something I got a "D" in, in City College. "Introduction to Networking" is something I got a "B" or "C" in, because I am much better at learning static (unchanging) information and then applying it to a problem. But math is required for programming... and math is something I have never been good at. Long story short... H E L P !!! |
||||
|
Calm luposian, I don t think will be necessary program one complex behavior or action to create one good AI in coppercube, let s start with the good principles for one good AI (for Friendly NPC and enemy) (obs: for friendly NPC the sven have one extension and one video in his youtube channel, can be interesting give one look in his work) First step: What you want your NPC do? when he will do? write this in one paper, because the base of one AI is one condition determinate one action. Example: When the enemy see (detect in his field of view from his sensor) (this is the condition), the enemy attack the player (this is the action). Second step: Think how I can do this? Is possible to be made with the resources and tools I have? (in case of coppercube many AI things can be make) Third step: tryieng to make the AI in the program (coppercube) |
||||
|
One interesting exercice: create your enemy, apply the in built Ai from coppercube, add the name of tag of the target the enemy will execute the actions. In player create parented for your player one static mesh without colison and without the behavior colisior, put one full color black image, like the texture ad select the material type transparent add (the option that make the object appear invisible), add to this static mesh the behavior of AI and add inert, add to the tag for your enemy attack this static mesh parent with your character. create one small sensor around or enemy with the option near and distant, when the static mesh is near of sensor set variable player1 = 1, if distant player1 = 0. select to in your enemy behavior AI the action to shot with raycast to make damage in your player (for raycast shot work is necessary the character is with the AI and option this is the player). In the scene put before the scene render, set variable player1 = 0; every few seconds the action if variable is: player1= 1, action set visible the static mesh; else one action if variable is, now with the condition the player1 = 0, action set the static mesh invisible. the last step is make the static mesh not visible in editor. Now test and see the result (I can forget something but the principle is basic this) If is everything ok, you will had made you first simple Ai system using in built extensions from coppercube. The basis is for AI basic is sensor to detect and option of actions for the AI execute, for manage one AI we use variables and conditions to compare when the AI will make something, the action will depends from what you want to do (if you want the enemy for example grab the player will be necessary you have one action extension that allow you program with the visual script the step at step how the enemy with this (distance the enemy can grab, the change of animations, etc). I hope these informations help understand the AI creation can be made without one complex system script with one advanced math. AI is one system that cover one list of conditions to apply actions according the conditions programmed by one human being, if you ask one AI to do something that is not listed in his possible list of conditions, the AI will answer like one human being, the AI will do nothing because the AI don t know what do. Think in this and try make something in your pc, after this write the results for we be able to help better (at least try to make the exercise I wrote) Thanks the attention |
||||
| [ 1 2 ] Page 2 of 2 |
|
|