GameMaker: Studio

GameMaker: Studio

查看统计:
AliaNeptune.ttv 2017 年 9 月 9 日 下午 4:05
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
< >
正在显示第 16 - 30 条,共 35 条留言
Almond Meal 2017 年 10 月 12 日 下午 4:52 
If you want to add combos where the play presses different buttons for different moves. In then in the create event we’ll create a new variable and call in button. At the top of the step event before everything else:

if keyboard_check(ord("A"))
button = 0
if keyboard_check(ord("S"))
button = 1
if keyboard_check(ord("D"))
button = 2

Or whatever keys/ buttons you want. Then in the part with the stages you’d change them to something like:

if stage == 0
{
if button == 0
{
// attack version 1
countdown=30 // length of attack
}
if button == 1
{
// attack version 2
countdown=30 // length of attack
}
if button == 2
{
// attack version 3
countdown=30 // length of attack
}
stage+=1
}

Some people would say to use the “case” command when using this many ‘if’ statements, up to you what you use. If you want different attacks depending on the order you press the keys, that gets a bit more complex but I can help you with that if you want.
AliaNeptune.ttv 2017 年 11 月 6 日 下午 5:17 
Hi Almond I wanted to give you an update. I was fiddling with the combos but realized this is taking me a while to implement so I decided to do smaller things like double jumps and enemy variaties before I get back to doing the more advanced stuff (attack combos).

1) I have a question about GMS coding structure.
So let's say:
if place_meeting 1 pixel above a wall obj
{
X
if (A == 0)
{
do this
}
Y
}
If I also wanted to add something else like, play sound in the X or Y area, this applies to the 'if place_meeting 1 pixel above a wall obj' and not the 'if statement' within it, right?

2) Does the X or Y placement matter? Is X prioritized over the Y? Is coding above put at the top because it's more important?

3) Another question, how do you figure out why something's not happening when you don't get an error? (Is it think, and think hard? haha)
I've previously implemented double jumps in a previous project successfully so I'm using the same logic and coding in this project. The game works fine but the double jump just doesnt happen (as if I added nothing), so how do you figure out what you need to add or what you're missing? I kind of wish I would get an error so it can tell me but it has to be because i'm missing something, or maybe the placement of code is wrong, or something is conflicting with it.

Thanks again Almond.
Almond Meal 2017 年 11 月 6 日 下午 6:08 
Q1) You are correct, both X and Y are within the place_meeting. The sound would play independently of the if statement within it.
Q2) Code runs from top to bottom, X would run first and then Y (but all in the same step) in this scenario. For choosing one for the audio to play would normally not matter.
Q3) Normally in cases like this I draw the variables that are involved so I can see in more details what is going on. I also use show_message to make a message pop up when something is meant to happen, it is useful because it pauses the game. You can also use show_message to show you a specified variable for that one step. I am going to assume that you have set up a variable so that there is a limited amount of jumps. I would check to see if it gets reset when the player lands and that both the normal ground jump and the mid-air jump are not used in the one button press.
I hope this helps.
AliaNeptune.ttv 2017 年 11 月 7 日 下午 3:48 
Okay thanks for the info. So the reason my jump wasn't going through was because I forgot that I had a grounded variable and the double jump would only apply if the player was grounded. -_-

The troubleshooting: You draw the variables as in figuratively or literally? Is it possible to only use the show_message when I want it to as in a simple code to add or remove when I'm trying to fix something/a bug?

If you recall, the enemy attack throws a bone and when collides with the player 3 times the player dies. Easy stuff because drag n drop. How would I make an enemy that does a melee attack? My player attacks draws a hitbox, I assume it would be similar. Can you elaborate on the steps I would need to do?
Almond Meal 2017 年 11 月 7 日 下午 4:53 
It is good to hear you got the double jump sorted.
As for the drawing variables, I do mean literally. Say you have a countdown variable for something to happen, then you can put in its draw event:

draw_text(x-64,y-64,countdown)

That way you can watch the countdown variable. It should turn it into a string if it is the only variable you put it there, otherwise you would have to use string(). For example:

draw_text(x-64,y-64,"Countdown: " + string(countdown) + "#Cooldown: " + string(cooldown))

For the melee attack, that can be as complex as you want it to be. You could simply use the same code you used for the bone throw as just make it shorter range. You could use the same code you have for the player’s melee attack instead. Whatever you choose, you’ll probably need to do a couple of things.

Check the distance to the player
Check which way to attack
Add a gap between attacks

The distance check is not difficult. I know you already know this but I’ll but it here anyway. You can use distance_to_object or point_distance (my preference). As for the direction of the attack, a lot of platformers have enemies attack in only two ways (left and right). To find which way you can use something along the lines of:
sign(Player.x – Enemy.x)

Which will give -1 if the player is to the left of the enemy, 1 if to the right and 0 if they share the exact same x value. For the gap, you can add a cooldown variable that counts down every step. Once it reaches zero if the conditions are met (such as distance to player and if they are on the ground) it will pick an attack if it has multiple, execute that attack and reset the cooldown (different attacks can have different cooldowns based on the time the attack takes and how long you would like the gap between attacks is). I am happy to go through this in more detail if you would like.
AliaNeptune.ttv 2017 年 11 月 16 日 下午 5:22 
Hi Almond. What's the variable to make the bone distance shorter for the enemy melee? I have bone.speed, bone.direction...

Right now I'm trying to use my player attack and hitbox coding for the enemy attacks for more versatility in attacks and so the player can dodge attacks... I feel as though using the bone coding but shorter is like a guaranteed hit on the player?
Almond Meal 2017 年 11 月 17 日 上午 1:59 
For the melee attack, all you need to do is add an alarm or your own countdown code that destroys it after a short amount of time.
If you feel it is too much of a certainty there are a few things you can do. I suggest you could add a little something that indicates when the enemy is about to attack. Something small like the enemy stops for a split second, or an animation or sprite change would work too.
AliaNeptune.ttv 2017 年 11 月 17 日 下午 7:39 
Can you brief me on the alarm event/system? What are some examples when i would use it?
How would I add invincibility frames after getting attacked?
Almond Meal 2017 年 11 月 17 日 下午 8:42 
The manual will give you a more in-depth explanation, but here is the short version. Whatever you set an alarm to is the amount of steps until it activates. If you set an alarm to 30 and the room speed is 30, then it will take one second to activate. You can set it to a variable if you want (like health, or score or even your own variable). It will only activate once until it is reset again. You can reset it in the alarm event to make a loop. If you reset an alarm before it is activated only activate once the latest setting is done, which means that if you have an alarm that set when the player collides with an object, the alarm will only activate once the player leaves the object.
I’ll give you two suggestions to choose from for the invincibility. The first one is to have a variable the player hold which indicates the player is invincible. At the start of every event that would damage the player it checks whether the variable is set to true or not. If it is false, it runs the normal code plus it set the variable to true and sets and alarm. If true, nothing happens. The alarm then sets the variable back to false again.
The second is to use a parent object for the player and the children are different states the player can be in. One for normal, one for invincibility and if you want you can add one each for climbing or swimming or whatever. This way you can have different controls for each state and still have enemies and objects treat them all the same (including distance checks and collisions if you want).
I think the first one might suit you better, it is neat, simple and works well. From what I’ve heard most people prefer to have it all in one object rather than splitting it and using the parent method. That said, I thought I’d suggest it anyway in case you think you should use it.
Sappy Secretary 2017 年 11 月 20 日 上午 12:35 
PLEASE SOMEONE HELP ME WITH CODING MESSEGE OF YOU WANT TO HELP I NEED HELP WITH PLAYER MOVEMENT PLEASE
Almond Meal 2017 年 11 月 20 日 上午 1:33 
引用自 DANNNNN
PLEASE SOMEONE HELP ME WITH CODING MESSEGE OF YOU WANT TO HELP I NEED HELP WITH PLAYER MOVEMENT PLEASE

I replied to your question in the other discussion you posted.
最后由 Almond Meal 编辑于; 2017 年 11 月 20 日 上午 1:35
AliaNeptune.ttv 2017 年 11 月 20 日 下午 1:46 
Hi Almond, so I think I have it, but i'm missing something. Everytime the player gets hit, it resets the i-frames; making the player forever invincible. How do I make it so it does not reset i-frames on each hit?
This is in the colliding with bone code in case I did something wrong here:
if (invincible = false)
{
health -= 35;
invincible = true;
alarm[1] = 100;
}

Also, how can I make it so the bones only disappear when it hits and subtracts health from player?
Almond Meal 2017 年 11 月 20 日 下午 3:32 
I took a look at the code you showed me and everything looked okay. I even tested it myself to make sure and it worked for me. I do not know what is wrong, there may be some other code which is affecting it. You can draw the alarm so you can watch it countdown, this way you may be able to pinpoint the cause. It will sit on -1 when not counting down.

draw_text(x,y,alarm[1]);

As for removing the bone only when not invincible, one way is to put the code within the player object, in their collision with the bone event. For example:

if (invincible == false)
{
health -= 35;
invincible = true;
alarm[1] = 100;
with other
{
instance_destroy();
//other codes the bone may have had
}
}

Do not forget to remove the bone’s collision event if you are going this way.
AliaNeptune.ttv 2017 年 11 月 21 日 下午 2:34 
Hi Almond, so it sat at -1 when I started, but when I get hit it turns into 100, and stays 100. Then I noticed that I didnt have an alarm at all (I accidently put in a different object) so I added it and now it counts down. Now it consecutively counts down from 100 to 0 and repeats immediately back at 100. This means that as long as its counting down, I virtually cannot die still. How do I fix this to only count down when I get hit?
Almond Meal 2017 年 11 月 21 日 下午 3:09 
I’m not too sure on this one but two thoughts comes to mind. As soon as it finishes the countdown the player is then vulnerable to attacks again. That means that very step, if a bone is flying through it will collide, hurt the player and start the invincibility once again. You would see if the health is going down though. You can do some checks to find out. You can put some show_message commands in the alarm and in the collision events (within the invincible check).
The other one would be that in the alarm event it both resets itself AND does not set invincible to false; that is if you had it so it sets it to true or you had a different variable, for example invisible instead of invincible (It would likely not cause an error because you are setting the variable and not addressing it). Seems unlikely but I recommend double checking.
< >
正在显示第 16 - 30 条,共 35 条留言
每页显示数: 1530 50

发帖日期: 2017 年 9 月 9 日 下午 4:05
回复数: 35