GameMaker: Studio

GameMaker: Studio

View Stats:
How to stop enemy movement
Advice please!

I have if distance to player < x then enemy state = chase
but I also have if enemy's hit != 0, enemy gets knocked back.

The enemy chase gets kind of "cancelled" by the knockback so when the enemy is chasing and gets hit, it doesnt get knockbacked at all because of the chase.

How can I fix this so the enemy can chase, but when it's hit, it won't chase anymore and just do the knockback coding? :c
< >
Showing 1-15 of 35 comments
Almond Meal Sep 9, 2017 @ 5:18pm 
You need to prevent the enemy from reinstating the chase while it is being knocked back. I’d suggest where it checks the distance between the player and the enemy you also check if the enemy is being knocked back. Something like:

if point_distance(x,y,player.x,player.y) < 200 and hit == 0
state = “chase”

if point_distance(x,y,player.x,player.y) > 200 and hit == 0
{
state = “idle”
speed = 0 //if too far away, stop chasing
}


if hit != 0
{
state = “knockback”
//Knockback code
}

I hope this helps, let me know if you need any more assistance.
AliaNeptune.ttv Sep 10, 2017 @ 6:40pm 
Thank you, this helped.

Would you happen to know how to add pauses? For example a two second pause before it enters the chase state again?
Almond Meal Sep 10, 2017 @ 8:04pm 
I can certainly help you with that. In the enemies create event make a new variable, for this example we’ll call it ‘cooldown’. Basically, you make cooldown decrease each step and with the chasing code check to see if cooldown is below 0. For example.
When the enemy gets hit:

cooldown = 120 //Or room speed time the number of seconds

In the step event:

cooldown -= 1
if cooldown <= 0
and point_distance(x,y,player.x,player.y) < 200
and hit == 0
state = "chase"

Depending on how you set it up, you may not need to check if hit equals 0 anymore. I am always happy to help. Let me know if I can help you with anything else.
Trainiac Sep 12, 2017 @ 1:28pm 
If you want to be lazy, you could try making the knockback twice as fast as the chase speed and make the enemy always chase you in that radius.
AliaNeptune.ttv Sep 12, 2017 @ 6:16pm 
@Train Thanks! that also helped a lot. I totally forgot I could be lazy and do that. *facepalm*

@Almond I'm currently workin on your advice now. Thank you for the help! Would you prefer I add you maybe and message you there for advice?

edit: I also forgot that I could just make sure that the enemy is touching the ground in order to chase, so it's exactly how I want it now. :I haha
Last edited by AliaNeptune.ttv; Sep 12, 2017 @ 6:44pm
supware Sep 13, 2017 @ 5:23am 
The simplest concievable way is to make a variable (let's continue the trend and call it cooldown) which decreases by 1 per step if it is > 0. When the enemy gets hit, set it to some constant ("cooldown = 30" for a 30-step/1-second delay etc.). Now simply tell the enemy to ignore the movement code if cooldown != 0, i.e.

"if cooldown = 0 {(your movement code)}"

or

"if cooldown != 0 exit; (your movement code)"
Last edited by supware; Sep 13, 2017 @ 5:25am
Almond Meal Sep 17, 2017 @ 5:14pm 
I am happy to see you found a solution that works for you. I believe that the discussion forums is a great place for advice. If someone has a problem then it is likely someone else is having the same problem. As seen in this discussion, there is usually more than one way to solve them. When there are multiple solutions provided you can pick out the one that best suits your game or be inspired to create one of your own. I am always happy to provide my support.
AliaNeptune.ttv Sep 20, 2017 @ 7:18pm 
Hi Almond, I have another issue: can you explain player health? Am I using the wrong variables and or what am I missing?

In my player's create I have 'health = 100;'
Enemy throws a bone towards the player's x and y at the time.
In the player's collision with the bone i have 'health -=35;' and 'if health <= 0 {game_restart()}
This means it will subtract 35 from the player's health right?
But when I test it, the player always dies in 1 hit and not the intended 3 hits.
Almond Meal Sep 20, 2017 @ 7:52pm 
All the code you have shown here are correct. Something I would check for is to see if the bone is destroyed when it collides with the player. If nothing stops the bone, the collision event will run every step and it would only take three steps for the player to run out of health. Let me know if you still need help with this.
AliaNeptune.ttv Sep 21, 2017 @ 12:17pm 
That was exactly it! Thanks Almond.

So I'm currently implementing a game over screen. The room is large, but the window only displays a certain amount and follows the player.
I'd like to draw text like "game over, r to restart" where ever the player's display is.
I'm currently using ww = window_get_width(), wh = window_get_height()
draw_text(ww/2,wh/2,"Game Over")
This displays on the top left alignment of the exact window size in the room, but not where the player's screen is.
Is there something specifically for the game window since it is constantly changing?

Edit: References: https://docs.yoyogames.com/source/dadiospice/002_reference/windows%20and%20views/the%20game%20window/index.html
Last edited by AliaNeptune.ttv; Sep 21, 2017 @ 12:19pm
Almond Meal Sep 21, 2017 @ 3:38pm 
The simplest way would be to put that code in the Draw GUI event, that always follows the view, as in, for the x and y (0, 0) will always be the top left of the view. For everything else you would want to use view_xview and view_yview. For example:

draw_text(view_xview + 32, view_yview+32, "Apples: " + string(apples))

Because you want to have the text displayed in the very centre you will need to make a few adjustment because by default text is create from the top left of the position you set it to. You can use the following code to adjust the alignment of your text.

draw_set_valign(fa_middle)
draw_set_halign(fa_center)
//Your text
draw_set_valign(fa_top)
draw_set_halign(fa_left)

In cases like this it is always a good idea to reset it back to the original once you’re done with it as show here. Hope this helps.
AliaNeptune.ttv Sep 22, 2017 @ 12:30pm 
Oh! All I did was change event to draw gui and it's where I want it. Thank you! Can you explain a bit more about gui? It focuses more on the current views instead of the room?

Another question, what do you mean reset the valign and halign back to the original? You mean for a different game?
Last edited by AliaNeptune.ttv; Sep 22, 2017 @ 1:06pm
Almond Meal Sep 22, 2017 @ 9:15pm 
GUI is the general user interface. It is commonly used for things you would always want in view, such as ammo count, health bar and lives remaining. I believe it runs after the normal draw event, therefore everything drawn in the draw GUI event is on top of everything drawn in the normal draw event. The depth of the object still determines the order though. I copied this from a message I sent to someone else who was having issues with the draw GUI:

Some things to remember when using draw gui event, when using drawing codes such as draw_text, 0,0 will be the top left of the view. But when using other codes such as instance_create, 0,0 will be the top left of the room, not the view.
That means: in the draw gui event:

draw_text(32,32,”Hello”)
instance_create(32,32,obj_a)

will be in two different positions.

draw_text(32+view_xview,32+view_yview,”Hello”)
instance_create(32+view_xview,32+view_yview,obj_a)

will also be two different spots, the text will fly off the screen as the view moves.
But:

draw_text(32,32,”Hello”)
instance_create(32+view_xview,32+view_yview,obj_a)

IS in the same spot.


As for the text alignment, by reset I mean setting it back to the default. Changing some things that change how to drawing works will often change it for all objects (such as the text alignment and colour blending), not just the object running the code, therefore you probably want to change it back after you have drawn the things you wanted it to change. In the example I showed you:

draw_set_valign(fa_middle)
draw_set_halign(fa_center)
//Your text
draw_set_valign(fa_top)
draw_set_halign(fa_left)

You can see that it changes back to the default fa_top and fa_left after it has drawn the text. If it didn’t have this and in another object you had something like:

draw_text(view_xview + 32, view_yview+32, "Apples: " + string(apples))

Then some of the text might be drawn off the screen instead of from left of the screen and towards the centre. I hope this clears things up.
AliaNeptune.ttv Oct 12, 2017 @ 11:29am 
Hi Almond!
So I just managed adding air attacks which the method i used was kind of simple it just took me forever to figure it out and probably will need to be reworked eventually -_-

but a single attack+animation is not doing it for me, how would I go with adding combo/chain attacks?
Almond Meal Oct 12, 2017 @ 4:52pm 
There is a number of ways you can achieve this. I’ll give you my suggestion but it will be quite ambiguous so you can integrate it with your own code you already have. We’ll create a new variable and I’ll call it countdown and set it as 0 in the create event (was going to call it cooldown but I used that already) and we’ll do the same with a variable called stage. The rest will go in the step event.
For a chain attack, one that is just the same button over and over again you can use something like:

countdown -= 1
if countdown < -30
stage = 0 //resets the attack stage if the player doesn’t attack
if keyboard_check(ord("V")) // or your attack button
if countdown <= 0
{
if stage == 0
{
// your normal attack
stage+=1
countdown=30 // or length of attack plus a little gap
}
if stage == 1
{
// your second attack
stage+=1
countdown=30 // Again, the length
}
if stage == 2
{
// lets say this is the final stage
stage = 0 // reset to start the chain again.
countdown=30 // or length of attack plus a little gap
}
}
< >
Showing 1-15 of 35 comments
Per page: 1530 50

Date Posted: Sep 9, 2017 @ 4:05pm
Posts: 35