CalculateNPC()
{
for (id = 0 2<id id++)
{
if(NPC[id] Is Alive AND NPC[id] Is Ready To Attack)
{
if(PlayerPos.Y-3 > NPC[id].Vector.Y)
{
NPC[id].Vector.Y -= 50 * TimeDelta;
} else if(PlayerPos.Y+3 < NPC[id].Vector.Y) {
NPC[id].Vector.Y += 50 * TimeDelta;
}
Then etc if the NPC is in these positions in the Y Axis then set what lane the NPC is in to spawn the projectiles.
}
}
}
Align Y Axis With Player, But Try Too Guest.
I have a idea how to create AI in my game, but how can I add a guesting or stupidity so it's not always going to align it's self with the player.
I have a 2D game, but 3D rendering and what I have are 3 lanes the player is in. I want to spawn maybe 2 NPCs that would get in the lane the player is in and start spawning projectiles when the NPC has reached the goal lane.
He is what I would wright to calculate NPC movement in Pseudo code.
That's something I would write, but how can I randomize it or make the AI act like it's trying to guest where the player will go in which lane next and also avoid running into other NPCs at the same time?
[Edited by - ajm113 on May 29, 2009 1:46:59 PM]
Check out my open source code projects/libraries! My Homepage You may learn something.
You would need to explain better how your game is meant to work, I think that you mean Guess(A try on one of the possible awnsers to find the correct one) and not Guest(Someone(A friend maybe) that you have on your house for a short period of time).
If you can't quite explain how your game is meant to work, then try this to find out yourself how to implement the AI:
1 - make a list of what the NPC MUST do.
2 - then write(not in any programing language, but on your own language) all steps it requires to do.
3 - for all actions, and for all steps, write substeps.
4 - repeate 3 for all substeps untill they are not divisible anymore.
5 - put then in order as they need to be used.
6 - put it all on the desired programing language.
I will be something like:
Walk Forward
|- trace a raycasting to check for possible colisions
|-|- calculate colisions with some geometry formula i don't know!
|-|- return it as a boolean for the previous step
|- if there is no collision
|-|- just walk some steps
|- if there is collision
|-|- do something, maybe walk to the right
|- repeate untill it reach a desired destination
Do something else
|- somehting that must be done to be able to do something else
.
.
.
paper and drawnings are your best friends when you need something done, especialy a program!
If you can't quite explain how your game is meant to work, then try this to find out yourself how to implement the AI:
1 - make a list of what the NPC MUST do.
2 - then write(not in any programing language, but on your own language) all steps it requires to do.
3 - for all actions, and for all steps, write substeps.
4 - repeate 3 for all substeps untill they are not divisible anymore.
5 - put then in order as they need to be used.
6 - put it all on the desired programing language.
I will be something like:
Walk Forward
|- trace a raycasting to check for possible colisions
|-|- calculate colisions with some geometry formula i don't know!
|-|- return it as a boolean for the previous step
|- if there is no collision
|-|- just walk some steps
|- if there is collision
|-|- do something, maybe walk to the right
|- repeate untill it reach a desired destination
Do something else
|- somehting that must be done to be able to do something else
.
.
.
paper and drawnings are your best friends when you need something done, especialy a program!
Sorry for the not so pepper english!
The AI is supposed to work like a 2D side scroll of a flying a aircraft or space craft and AI just fly left and right and try to attack you by aligning with the player.
That's what I'm trying to achieve, but I should have used X then Y to explain it. All I want to know is how can I have some type of randomness on the side when the AI goes left and right with the player. Another example I could have used was pong too as a example, but 2D side scroll is what I'm aiming for in my game's mod.
I did explain what I was trying to achieve if you looked at my pseudo code for a few seconds.
That's what I'm trying to achieve, but I should have used X then Y to explain it. All I want to know is how can I have some type of randomness on the side when the AI goes left and right with the player. Another example I could have used was pong too as a example, but 2D side scroll is what I'm aiming for in my game's mod.
I did explain what I was trying to achieve if you looked at my pseudo code for a few seconds.
Check out my open source code projects/libraries! My Homepage You may learn something.
Quote: Original post by ajm113
how can I add a guesting or stupidity so it's not always going to align it's self with the player...
how can I randomize it or make the AI act like it's trying to guest where the player will go in which lane next and also avoid running into other NPCs at the same time?
Those are three distinct problems. The first is pretty simple, just make the NPCs' stimulus response lag a bit (as does the player's), such that they're reacting to an old game state. You could implement that using a "first in, last out" queue of game states with a fixed size, and doing all your AI in the oldest state in the queue (can't think of a simpler way but there are others).
Guessing where the player will go is a hideously complex problem, so I don't think it's exactly what you meant. To optimize such a guess would require the AI to (at least) evaluate the utilities of the player's possible actions over time and infer the probability of their execution. Could be done, but shouldn't.
As for the last problem, making the NPCs avoid hitting each other, that's an instance of "obstacle avoidance". I could propose a simple solution but I don't see any applicability. If the NPCs are just getting to the same level as the player then shooting him, they would either be constantly separate on the X axis, or would occupy the same column and constantly hit into each other. In both cases there's no need for them to steer around each other. It'd help if you described your game in more detail.
Alright, well I have a game that works like Audio-Surf and I want to add AI, for now since I'm new with AI I'm trying to keep it simple and only allow 2 or 1 NPC in one X position. The NPCs can't move forward or backwards, but only move left and right (Up or Down) with the player in front of them. The player has the same laws. Can't move forward or backwards and can only move left and right.
I only have the player and AI 5 lanes to move around in, its not a car game, but I like to use lanes as a easier term to define the size like a grid almost. The lanes size are 1.0 each. So the playing field height is -4.0 to 4.0.
I was thinking on using a random function to tell if the NPC should move left or right out of the player's position. So if 1 move the other way, for a few seconds and if 0 move with the player.
Have I cleared up my goal a little?
Thanks, Ajm.
I only have the player and AI 5 lanes to move around in, its not a car game, but I like to use lanes as a easier term to define the size like a grid almost. The lanes size are 1.0 each. So the playing field height is -4.0 to 4.0.
I was thinking on using a random function to tell if the NPC should move left or right out of the player's position. So if 1 move the other way, for a few seconds and if 0 move with the player.
Have I cleared up my goal a little?
Thanks, Ajm.
Check out my open source code projects/libraries! My Homepage You may learn something.
Is all you need is a kind of simple strategy in order to let the NPCs decide what lane to move to?
In this case what about a randomiser that "decides" only if a NPC guess the next player position or not, that is you roll dice and if the score is greater than a predetermined threshold the NPC guesses correctly and performs the required action(s) to get to the correct lane, otherwise pick any other lane randomly and let the NPC go there.
The threshold would determine how clever the NPC is.
You can change this threshold dynamically in order to have a variable cleverness of the NPC.
Also you can define the frequency at which the NPCs take decisions or define if an NPC can change mind during the travel to the current desired lane.
However, it is important to have clear the locomotion model and other details such as:
Can two or more NPCs occupy the same lane?
Do agents move through a velocity or do they just jump lane by lane?
In this case what about a randomiser that "decides" only if a NPC guess the next player position or not, that is you roll dice and if the score is greater than a predetermined threshold the NPC guesses correctly and performs the required action(s) to get to the correct lane, otherwise pick any other lane randomly and let the NPC go there.
The threshold would determine how clever the NPC is.
You can change this threshold dynamically in order to have a variable cleverness of the NPC.
Also you can define the frequency at which the NPCs take decisions or define if an NPC can change mind during the travel to the current desired lane.
However, it is important to have clear the locomotion model and other details such as:
Can two or more NPCs occupy the same lane?
Do agents move through a velocity or do they just jump lane by lane?
As I understand you're describing something like those old LCD games, where objects occupy a few discrete positions, and move at a certain rate, is that right?
Either way Thunder0ne is right. Each enemy moves to the lane where the player be when his (the enemy's) projectiles reach the other side. Their guesses will get worse as the velocity of projectiles decreases, so I take it that they're pretty fast. The predicted position is equal to the distance between the player's and enemy's lanes divided by the velocity of the projectile, times the player's velocity, plus the player's lane position:
position = ( ( [distance between player lane and enemy lane] / [velocity of projectile] ) * [velocity of player] ) + [pos. of player]
The question is whether the sign of the player velocity changes, and it can become be positive, negative, or 0, depending on what the player does. So the AI has to guess which decision the player will make. You just have to assign probabilities to player inputs [+], [-], and [0]. Naively you could make them equal, but that's probably unconvincing: in reality, the player will usually change lanes rather than stay, and at the top and bottom edge lanes they will never move up or down respectively (because they can't). Modify your probabilities accordingly. Generate a random number and test which range (within P(positive) + P(negative) + P(zero) ) it falls into, and set the predicted player velocity accordingly (multiply by 0, -1, or 1).
You could go far deeper with the prediction mechanism if you wanted your game to actually beat players.
Either way Thunder0ne is right. Each enemy moves to the lane where the player be when his (the enemy's) projectiles reach the other side. Their guesses will get worse as the velocity of projectiles decreases, so I take it that they're pretty fast. The predicted position is equal to the distance between the player's and enemy's lanes divided by the velocity of the projectile, times the player's velocity, plus the player's lane position:
position = ( ( [distance between player lane and enemy lane] / [velocity of projectile] ) * [velocity of player] ) + [pos. of player]
The question is whether the sign of the player velocity changes, and it can become be positive, negative, or 0, depending on what the player does. So the AI has to guess which decision the player will make. You just have to assign probabilities to player inputs [+], [-], and [0]. Naively you could make them equal, but that's probably unconvincing: in reality, the player will usually change lanes rather than stay, and at the top and bottom edge lanes they will never move up or down respectively (because they can't). Modify your probabilities accordingly. Generate a random number and test which range (within P(positive) + P(negative) + P(zero) ) it falls into, and set the predicted player velocity accordingly (multiply by 0, -1, or 1).
You could go far deeper with the prediction mechanism if you wanted your game to actually beat players.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement