Discuss Scratch

Nehal1234
Scratcher
500+ posts

How to make a computer controlled character?I need help!

I am working on a fighting game that will have a 2 player mode along with a mode where you fight a computer controlled character.Does anyone know how to program the computer controlled character?
TheAwesomeMaster
Scratcher
1000+ posts

How to make a computer controlled character?I need help!

whenright arrowkeypressedmove10steps

whenleft arrowkeypressedmove-10steps

This is one of the most basic options, there are some more complicated ones too.
deck26
Scratcher
1000+ posts

How to make a computer controlled character?I need help!

The computer controlled character will presumably want to move towards the player and it may be useful for it to know how close it is. So the following blocks might be useful.

pointtowardsplayerifdistancetosprite<5 thenyourattackcodehereelsemove5steps
It becomes more complicated if there are obstacles that the attacker has to go round.
Ermagerd117
Scratcher
19 posts

How to make a computer controlled character?I need help!

Try doing this for smooth movement
whenclickedforeverifkey apressed?thenmove-10stepsifkey dpressed?thenmove10steps


If you need anything else, Don't be afraid to ask!

Last edited by Ermagerd117 (Oct. 12, 2015 15:07:52)

deck26
Scratcher
1000+ posts

How to make a computer controlled character?I need help!

There's no point giving scripts controlled by key presses for the computer controlled character!
Nehal1234
Scratcher
500+ posts

How to make a computer controlled character?I need help!

deck26 wrote:

The computer controlled character will presumably want to move towards the player and it may be useful for it to know how close it is. So the following blocks might be useful.

pointtowardsplayerifdistancetosprite<5 thenyourattackcodehereelsemove5steps
It becomes more complicated if there are obstacles that the attacker has to go round.

There are obstacles like ledges and floating platforms.
Nehal1234
Scratcher
500+ posts

How to make a computer controlled character?I need help!

Ermagerd117 wrote:

Try doing this for smooth movement
whenclickedforeverifkey apressed?thenmove-10stepsifkey dpressed?thenmove10steps


If you need anything else, Don't be afraid to ask!

Thanks!
Do you know how to program when someone takes a hit,they lose health?
MegaApuTurkUltra
Scratcher
1000+ posts

How to make a computer controlled character?I need help!

Basic AI:
Make the AI 100% perfect, but then add “mistakes” randomly. The amount of “mistakes” determines the difficulty.
Example: If you're making Pong, then make the AI paddle follow the ball perfectly but sometimes make it lag behind or stop all of a sudden.
When to use this: If there is only one thing that the AI needs to do, eg follow the pong ball with their paddle

More complicated AI:
Sophisticated AIs use states, which basically define what the AI is supposed to do at some point. Each state has triggers, which tell the AI when to enter that state, and actions, which are what the AI does when it's in that state.
Example: If you were to make an air hockey game, you might have these states
  1. Hit the puck towards the player's goal
  2. Block an incoming puck
  3. Go backwards around the puck
  4. Move around randomly / do nothing
The triggers for each would be
  1. Enter this state if the puck is in front of the AI paddle but on the AI's side
  2. Enter this state if the puck is on the AI's side, in front of the AI paddle, and going towards the goal
  3. Enter this state if the puck is on the AI's side but behind the AI paddle
  4. Enter this state if the puck is in front of the AI, on the enemy side, and going towards the enemy
Triggers can also just be random, eg if you have a bunch of different types of moves for your fighting game then you'll need to choose a random one.
So an example game might go like
Player hits puck towards AI goal
AI enters blocking state, successfully blocks puck
AI enters hitting state, hits the puck towards the player goal
AI enters do nothing state while the puck goes towards the player goal
Player blocks the puck and hits it back
AI enters blocking state, fails to block the puck. The puck is now behind the AI
AI enters go backwards state, goes around the puck. The puck is now in front of the AI
AI enters blocking state again, successfully blocks the puck
and so on…

You can add random mistakes to this as well, depending on whether your AI ends up being hard to beat or not.
When to use: When there are multiple things your AI needs to do depending on the environment.

HTH
Nehal1234
Scratcher
500+ posts

How to make a computer controlled character?I need help!

MegaApuTurkUltra wrote:

Basic AI:
Make the AI 100% perfect, but then add “mistakes” randomly. The amount of “mistakes” determines the difficulty.
Example: If you're making Pong, then make the AI paddle follow the ball perfectly but sometimes make it lag behind or stop all of a sudden.
When to use this: If there is only one thing that the AI needs to do, eg follow the pong ball with their paddle

More complicated AI:
Sophisticated AIs use states, which basically define what the AI is supposed to do at some point. Each state has triggers, which tell the AI when to enter that state, and actions, which are what the AI does when it's in that state.
Example: If you were to make an air hockey game, you might have these states
  1. Hit the puck towards the player's goal
  2. Block an incoming puck
  3. Go backwards around the puck
  4. Move around randomly / do nothing
The triggers for each would be
  1. Enter this state if the puck is in front of the AI paddle but on the AI's side
  2. Enter this state if the puck is on the AI's side, in front of the AI paddle, and going towards the goal
  3. Enter this state if the puck is on the AI's side but behind the AI paddle
  4. Enter this state if the puck is in front of the AI, on the enemy side, and going towards the enemy
Triggers can also just be random, eg if you have a bunch of different types of moves for your fighting game then you'll need to choose a random one.
So an example game might go like
Player hits puck towards AI goal
AI enters blocking state, successfully blocks puck
AI enters hitting state, hits the puck towards the player goal
AI enters do nothing state while the puck goes towards the player goal
Player blocks the puck and hits it back
AI enters blocking state, fails to block the puck. The puck is now behind the AI
AI enters go backwards state, goes around the puck. The puck is now in front of the AI
AI enters blocking state again, successfully blocks the puck
and so on…

You can add random mistakes to this as well, depending on whether your AI ends up being hard to beat or not.
When to use: When there are multiple things your AI needs to do depending on the environment.

HTH

I am actually doing this as a collab so is it okay if i copy and paste this post to my collab members?
deck26
Scratcher
1000+ posts

How to make a computer controlled character?I need help!

Nehal1234 wrote:

MegaApuTurkUltra wrote:

Basic AI:
Make the AI 100% perfect, but then add “mistakes” randomly. The amount of “mistakes” determines the difficulty.
Example: If you're making Pong, then make the AI paddle follow the ball perfectly but sometimes make it lag behind or stop all of a sudden.
When to use this: If there is only one thing that the AI needs to do, eg follow the pong ball with their paddle

More complicated AI:
Sophisticated AIs use states, which basically define what the AI is supposed to do at some point. Each state has triggers, which tell the AI when to enter that state, and actions, which are what the AI does when it's in that state.
Example: If you were to make an air hockey game, you might have these states
  1. Hit the puck towards the player's goal
  2. Block an incoming puck
  3. Go backwards around the puck
  4. Move around randomly / do nothing
The triggers for each would be
  1. Enter this state if the puck is in front of the AI paddle but on the AI's side
  2. Enter this state if the puck is on the AI's side, in front of the AI paddle, and going towards the goal
  3. Enter this state if the puck is on the AI's side but behind the AI paddle
  4. Enter this state if the puck is in front of the AI, on the enemy side, and going towards the enemy
Triggers can also just be random, eg if you have a bunch of different types of moves for your fighting game then you'll need to choose a random one.
So an example game might go like
Player hits puck towards AI goal
AI enters blocking state, successfully blocks puck
AI enters hitting state, hits the puck towards the player goal
AI enters do nothing state while the puck goes towards the player goal
Player blocks the puck and hits it back
AI enters blocking state, fails to block the puck. The puck is now behind the AI
AI enters go backwards state, goes around the puck. The puck is now in front of the AI
AI enters blocking state again, successfully blocks the puck
and so on…

You can add random mistakes to this as well, depending on whether your AI ends up being hard to beat or not.
When to use: When there are multiple things your AI needs to do depending on the environment.

HTH

I am actually doing this as a collab so is it okay if i copy and paste this post to my collab members?
The forum is open to all users to read so there can be no objection to that.
Nehal1234
Scratcher
500+ posts

How to make a computer controlled character?I need help!

deck26 wrote:

Nehal1234 wrote:

MegaApuTurkUltra wrote:

Basic AI:
Make the AI 100% perfect, but then add “mistakes” randomly. The amount of “mistakes” determines the difficulty.
Example: If you're making Pong, then make the AI paddle follow the ball perfectly but sometimes make it lag behind or stop all of a sudden.
When to use this: If there is only one thing that the AI needs to do, eg follow the pong ball with their paddle

More complicated AI:
Sophisticated AIs use states, which basically define what the AI is supposed to do at some point. Each state has triggers, which tell the AI when to enter that state, and actions, which are what the AI does when it's in that state.
Example: If you were to make an air hockey game, you might have these states
  1. Hit the puck towards the player's goal
  2. Block an incoming puck
  3. Go backwards around the puck
  4. Move around randomly / do nothing
The triggers for each would be
  1. Enter this state if the puck is in front of the AI paddle but on the AI's side
  2. Enter this state if the puck is on the AI's side, in front of the AI paddle, and going towards the goal
  3. Enter this state if the puck is on the AI's side but behind the AI paddle
  4. Enter this state if the puck is in front of the AI, on the enemy side, and going towards the enemy
Triggers can also just be random, eg if you have a bunch of different types of moves for your fighting game then you'll need to choose a random one.
So an example game might go like
Player hits puck towards AI goal
AI enters blocking state, successfully blocks puck
AI enters hitting state, hits the puck towards the player goal
AI enters do nothing state while the puck goes towards the player goal
Player blocks the puck and hits it back
AI enters blocking state, fails to block the puck. The puck is now behind the AI
AI enters go backwards state, goes around the puck. The puck is now in front of the AI
AI enters blocking state again, successfully blocks the puck
and so on…

You can add random mistakes to this as well, depending on whether your AI ends up being hard to beat or not.
When to use: When there are multiple things your AI needs to do depending on the environment.

HTH

I am actually doing this as a collab so is it okay if i copy and paste this post to my collab members?
The forum is open to all users to read so there can be no objection to that.

Thanks!
MegaApuTurkUltra
Scratcher
1000+ posts

How to make a computer controlled character?I need help!

Nehal1234 wrote:

MegaApuTurkUltra wrote:

Basic AI:
Make the AI 100% perfect, but then add “mistakes” randomly. The amount of “mistakes” determines the difficulty.
Example: If you're making Pong, then make the AI paddle follow the ball perfectly but sometimes make it lag behind or stop all of a sudden.
When to use this: If there is only one thing that the AI needs to do, eg follow the pong ball with their paddle

More complicated AI:
Sophisticated AIs use states, which basically define what the AI is supposed to do at some point. Each state has triggers, which tell the AI when to enter that state, and actions, which are what the AI does when it's in that state.
Example: If you were to make an air hockey game, you might have these states
  1. Hit the puck towards the player's goal
  2. Block an incoming puck
  3. Go backwards around the puck
  4. Move around randomly / do nothing
The triggers for each would be
  1. Enter this state if the puck is in front of the AI paddle but on the AI's side
  2. Enter this state if the puck is on the AI's side, in front of the AI paddle, and going towards the goal
  3. Enter this state if the puck is on the AI's side but behind the AI paddle
  4. Enter this state if the puck is in front of the AI, on the enemy side, and going towards the enemy
Triggers can also just be random, eg if you have a bunch of different types of moves for your fighting game then you'll need to choose a random one.
So an example game might go like
Player hits puck towards AI goal
AI enters blocking state, successfully blocks puck
AI enters hitting state, hits the puck towards the player goal
AI enters do nothing state while the puck goes towards the player goal
Player blocks the puck and hits it back
AI enters blocking state, fails to block the puck. The puck is now behind the AI
AI enters go backwards state, goes around the puck. The puck is now in front of the AI
AI enters blocking state again, successfully blocks the puck
and so on…

You can add random mistakes to this as well, depending on whether your AI ends up being hard to beat or not.
When to use: When there are multiple things your AI needs to do depending on the environment.

HTH

I am actually doing this as a collab so is it okay if i copy and paste this post to my collab members?
Yep
Nehal1234
Scratcher
500+ posts

How to make a computer controlled character?I need help!

MegaApuTurkUltra wrote:

Nehal1234 wrote:

MegaApuTurkUltra wrote:

Basic AI:
Make the AI 100% perfect, but then add “mistakes” randomly. The amount of “mistakes” determines the difficulty.
Example: If you're making Pong, then make the AI paddle follow the ball perfectly but sometimes make it lag behind or stop all of a sudden.
When to use this: If there is only one thing that the AI needs to do, eg follow the pong ball with their paddle

More complicated AI:
Sophisticated AIs use states, which basically define what the AI is supposed to do at some point. Each state has triggers, which tell the AI when to enter that state, and actions, which are what the AI does when it's in that state.
Example: If you were to make an air hockey game, you might have these states
  1. Hit the puck towards the player's goal
  2. Block an incoming puck
  3. Go backwards around the puck
  4. Move around randomly / do nothing
The triggers for each would be
  1. Enter this state if the puck is in front of the AI paddle but on the AI's side
  2. Enter this state if the puck is on the AI's side, in front of the AI paddle, and going towards the goal
  3. Enter this state if the puck is on the AI's side but behind the AI paddle
  4. Enter this state if the puck is in front of the AI, on the enemy side, and going towards the enemy
Triggers can also just be random, eg if you have a bunch of different types of moves for your fighting game then you'll need to choose a random one.
So an example game might go like
Player hits puck towards AI goal
AI enters blocking state, successfully blocks puck
AI enters hitting state, hits the puck towards the player goal
AI enters do nothing state while the puck goes towards the player goal
Player blocks the puck and hits it back
AI enters blocking state, fails to block the puck. The puck is now behind the AI
AI enters go backwards state, goes around the puck. The puck is now in front of the AI
AI enters blocking state again, successfully blocks the puck
and so on…

You can add random mistakes to this as well, depending on whether your AI ends up being hard to beat or not.
When to use: When there are multiple things your AI needs to do depending on the environment.

HTH

I am actually doing this as a collab so is it okay if i copy and paste this post to my collab members?
Yep
Thanks!
JokerDeath
New Scratcher
3 posts

How to make a computer controlled character?I need help!

What if the thing you want the computer to control is a fighting character and that character has to switch sprites and combos/attacks?
deck26
Scratcher
1000+ posts

How to make a computer controlled character?I need help!

JokerDeath wrote:

What if the thing you want the computer to control is a fighting character and that character has to switch sprites and combos/attacks?
Better to start your own new topic rather than necroposting. Share what you have and define what you're trying to achieve.
BigBrainBuster
New Scratcher
1 post

How to make a computer controlled character?I need help!

I need block code can anyone help. I need the code to make a cpu that I need in my game it would be awesome if one of you guys can help me.


-Love this chat though

Last edited by BigBrainBuster (Oct. 17, 2019 17:40:29)

deck26
Scratcher
1000+ posts

How to make a computer controlled character?I need help!

BigBrainBuster wrote:

I need block code can anyone help. I need the code to make a cpu that I need in my game it would be awesome if one of you guys can help me.


-Love this chat though
Please start a new topic rather than necroposting.
SirTypesALot
Scratcher
1 post

How to make a computer controlled character?I need help!

FARTY
lisagu
Scratcher
79 posts

How to make a computer controlled character?I need help!

Nehal1234 wrote:

Ermagerd117 wrote:

Try doing this for smooth movement
whenclickedforeverifkey apressed?thenmove-10stepsifkey dpressed?thenmove10steps


If you need anything else, Don't be afraid to ask!

Thanks!
Do you know how to program when someone takes a hit,they lose health?


Make a variable called ‘'Lives’' ;
Lives

At the beginning of the game, set ‘'Lives’' to 0

set Livesto0foreveriftouchingthe thing they get hit by?thenchange Livesby-1
help_with_scripts
Scratcher
100+ posts

How to make a computer controlled character?I need help!

Nehal1234 wrote:

Ermagerd117 wrote:

Try doing this for smooth movement
whenclickedforeverifkey apressed?thenmove-10stepsifkey dpressed?thenmove10steps


If you need anything else, Don't be afraid to ask!

Thanks!
Do you know how to program when someone takes a hit,they lose health?
If touching (enemy) and costume of enemy equals (attack) change health by 0 - (attack strength)

Powered by DjangoBB