#[How to make enemy do small hops instead of moving horizontally?] & [losing lives with collision]
90 messages ยท Page 1 of 1 (latest)
Try using alarms. For example, if you need your enemy to jump forwards every 1 second (60 frames), you can do something like:
Create Event
hop_distance = 10;
hop_height = -10;
alarm[0] = 60;
Alarm 0 Event
hsp = hop_distance;
vsp = hop_height;
alarm[0] = 60;
Step Event
if (grounded) {
if (afraidofheights && !place_meeting(x + hop_distance, y+1, [objGrassBlock, objWastelandBlock, objFireBlock])) {
hop_distance = -hop_distance;
}
hsp = lerp(hsp, 0, .2);
}
ooooo this seemed to have worked so thank you but the enemy does large and quick jumps whereas I want the hops to be shorter and it also seems to jump off platforms and even jumps in mid air off the screen
is there a way to fix this?
or should I create an invisible block as a barrier to stop the enemy but have no collision with the player?
would that be a good solution?
Okkk to make the hops smaller, you can fiddle with the hop_distance and hop_height variables. Smaller numbers make smaller hops
To make the jumps take longer, you can set the alarms to a larger number. 60 frames is 1 second, 120 frames is 2 seconds, etc.
Remember to set the one in the Create event and the one in the Alarm 0 event
ooo making the jump smaller fixed the issue of him jumping off the platforms
Good to hear! Anything else that needs to be fixed?
That's seemed to fix the problem that I had so thank you very much!!!!!!!!!
you are a legend
thxx
Hi I was wondering if you could also help me with another problem im having
I've setup a lives system for my player so when he collides with the player he loses 1 life
but when I collide with the enemy my player loses all the lives in one go super fast
I assume to combat this I would have to make a small delay or invulnerability time to my player when colliding with the enemy
any idea how I would go about doing this?
This is what I've got so far
soo I assume I would create a variable that's always set to false and
if I touch the enemy and that variable is false then lose a life then flip that variable to true for the amount of time I wanna be invulnerable?
but how would I put this into code?
if anyone can help
[How to make enemy do small hops instead of moving horizontally?] & [losing lives with collision]
Add another variable like this:
Create
invulnerable = false;
Then add a bit into the else statement of your Collision event:
Collide
...
else {
if (global.life > 0 && ! invulnerable) {
global.life -= 1;
invulnerable = true;
alarm[0] = 60;
}
}
And finally, use an alarm to reset the invulnerability variable.
Alarm 0
invulnerable = false;
I have added this to my code but my lives still get taken away immediately super fast
Oh whoops
ahh I see
I added a line into the collision event. Try that ๐ค
ahhh NICE it works perfectly
also if I were to make a powerup that made my character invulnerable for a set amount of time would It would work similar to this expect I would instead change the time for the alarm and take out the life stuff?
also I am trying to make it so that when I lose all my lifes my game restarts but it's not letting me use another else statement
would this be wrong?
Yesss exactly
Just let it out of the else statement
ahh ok I've taken it out of the else statement but
when I get done to 0 lives it doesnt restart until I get hit again
so I kinda have 4 lives instead of the 3 I set in global life
Oh yeah just put it in the Step event instead
The last if statement
Oh wait
nvm
You set the lives to check for < 0
So your character only dies when the counter reaches -1
Set it to <= 0 instead
ok so I've changed it like you said and it did the same thing but changing the 0 to 1 seemed to fix the problem so thank you so much
I have one more question good sir
and after this pls let me send u money for a coffee or something, you've helped me too much
I wanna make a pirana plant style enemy that stays stationary and shoots fireballs at the player but cant seem to find any tutorials for this
only like
enemies that move and shoot the player like a gun but
I also wanna make a powerup that lets the player shoot the same projectile
wait nvm I think I've found something ima try out
figured it out
all good
Im trying to make the invulnerability powerup like we talked about before
but for some reason it doesnt make me invulnerable
is this correct?
nvm I managed to fix it
I realised that the alarm thing was for frames so I was basically making myself invincible for a sec so I changed that
all working good now
hey, I was wondering if you could help me with something else
I wanna make it so that
I've created an invulnerability power up like we talked about before
and this is the code for
it
but i was wondering
how about's would I go around making it so for the duration that the alarm event is active it switches my character sprite to another?
NVM figured it out
lmao bro you keep figuring things out while I'm asleep ๐
You mean like a frog ?