• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Enemy AI platform

L

llxchay

Guest
Hey folks, I want to create a platform-style enemy, but I want him to walk randomly on a platform and when the player gets close to the enemy, I want him to attack. So can anyone help me?

I just want to make the enemy walk randomly on the platforms and when the player is in the ray of vision he advances against the player
 
Last edited by a moderator:

TsukaYuriko

☄️
Forum Staff
Moderator
Surely. What's your problem with the scenario you've described? Have you attempted any solution to implement this yet? If yes, please post all relevant code and the issues you have ran into. Or are you just looking for general pointers for how to approach this?
 

woods

Member
step 1
define your problem

step 2
post your relevant code( how does your enemy move? how does your enemy detect the player?)

step3
how have you tried to fix/adjust it?
 
L

llxchay

Guest
[QUOTE = "TsukaYuriko, post: 374365, membro: 28"] Certamente. Qual é o seu problema com o cenário que você descreveu? Você tentou alguma solução para implementar isso ainda? Se sim, poste todo o código relevante e os problemas que você encontrou. Ou você está apenas procurando indicadores gerais de como abordar isso? [/ QUOTE]
Surely. What's your problem with the scenario you've described? Have you attempted any solution to implement this yet? If yes, please post all relevant code and the issues you have ran into. Or are you just looking for general pointers for how to approach this?
just the basic.
create:
hsp = 0
vsp = 0
spd = 3
grv = 0.2
step:

vsp + = grv
move = hsp + spd

x + = move
 
L

llxchay

Guest
step 1
define your problem

step 2
post your relevant code( how does your enemy move? how does your enemy detect the player?)

step3
how have you tried to fix/adjust it?
Oh, i'm sorry...
 

TheouAegis

Member
Well if hsp is 0, move is going to be 0, and x+0 is just x, so it won't move at all.

You have literally provided next to nothing for anyone to help you with. You had given no code at first, nor did you actually specify anything about how the enemy is supposed to interact with the terrain and the player.
I want him to walk randomly on a platform
Do you mean you want him to walk back and forth on one single platform specifically while occasionally changing direction; or do you mean you want him to walk wherever and drop down to another platform when he reaches the edge of the one he's on but occasionally change direction? "Walk randomly on a platform" suggests the first idea, but you were hardly clear about it at all. Can the enemy jump from one platform to another? Does the enemy need to be affected by gravity at all or will it always be grounded?
when the player gets close to the enemy, I want him to attack
Attack how? Does he have a gun? Does he use a sword or other melee weapon? Will he charge at the player? Will he simply change direction and start moving in the direction the player is without changing direction ever again? Will he move toward the player, changing directions if the player gets on the other side of him? And will he attack indefinitely once he starts attacking or will he stop attacking after the player has gotten far enough away?

Then you haven't even said anything about how the enemy will be injured by the player, how it will respond to injuries (instant death, stun, knockback, knockup, i-frame flashing). Once you actually start to plan out what you want the enemy to do, then it should be easy for you to write code for that enemy.
 
L

llxchay

Guest
[QUOTE = "TheouAegis, post: 374388, member: 1973"] Bem, se hsp for 0, move será 0, e x + 0 será apenas x, então não será movido.

Você literalmente forneceu quase nada para qualquer um para ajudá-lo. Você não deu nenhum código a princípio, nem especificou nada sobre como o inimigo deveria interagir com o terreno e com o jogador.

Quer dizer que você quer que ele ande de um lado para outro em uma única plataforma especificamente enquanto ocasionalmente muda de direção; Ou você quer dizer que quer que ele ande onde quer que seja e desça para outra plataforma quando ele alcança a borda da que ele está, mas ocasionalmente muda de direção? "Ande aleatoriamente em uma plataforma" sugere a primeira ideia, mas você dificilmente estava claro sobre isso. O inimigo pode pular de uma plataforma para outra? O inimigo precisa ser afetado pela gravidade ou será sempre aterrado?

Atacar como? Ele tem uma arma? Ele usa uma espada ou outra arma branca? Ele irá cobrar do jogador? Ele irá simplesmente mudar de direção e começar a se mover na direção que o jogador está sem mudar de direção nunca mais? Ele irá se mover em direção ao jogador, mudando de direção se o jogador ficar do outro lado dele? E ele atacará indefinidamente assim que ele começar a atacar ou ele parará de atacar depois que o jogador se afastar o suficiente?

Então você nem disse nada sobre como o inimigo será ferido pelo jogador, como ele responderá a lesões (morte instantânea, atordoamento, knockback, knockup, i-frame piscando). Uma vez que você realmente comece a planejar o que você quer que o inimigo faça, então deve ser fácil para você escrever código para esse inimigo. [/ QUOTE]



I'm sorry, I'm a beginner. For the time being it's just an enemy that walks from one side to the other.
 

TheouAegis

Member
Like a Red Koopa from Super Mario Bros?

Set hsp to some value between 0 and 1, but not 0. If you set hsp to 0, the enemy can't move.
Every step, check if there is no ground ahead of the turtle, then reverse hsp.
Code:
if !place_meeting(x+sign(hsp)*4, y+1, obj_ground)
    hsp = -hsp;
What your code actually looks like depends on how the rest of your game is set up. This code just presumes all your ground tiles are objects called obj_ground.
 
L

llxchay

Guest
[QUOTE = "TheouAegis, post: 374400, membro: 1973"] Como um Koopa Vermelho do Super Mario Bros?

Defina hsp para algum valor entre 0 e 1, mas não 0. Se você definir hsp como 0, o inimigo não poderá se mover.
A cada passo, verifique se não há chão à frente da tartaruga, depois inverta hsp.
[código] if! place_meeting (x + sinal (hsp) * 4, y + 1, obj_ground)
hsp = -hsp;
[/código]

O que realmente parece seu código depende de como o resto do seu jogo está configurado. Este código apenas presume que todas as suas peças terrestres são objetos chamados obj_ground. [/ QUOTE]

exatamente, eu consegui fazer o que eu queria, eu consegui a dica dele e implementei o projeto, muito obrigado pela ajuda. e me desculpe pelo mau inglês, sou brasileira e não falo a língua
 

TsukaYuriko

☄️
Forum Staff
Moderator
The GMC is an English forum. Please keep your posts in English. Using translation services to translate from your native language into English is okay. Post contents must be in English, though.
 

woods

Member
not trying to be an ass ;o) its just as said above... there's nothing really to go on to help with

background info is definitely helpful ;o)
 
Top