Legacy GM HELP Player Dodging a Projectile

D

dawson2223

Guest
Hey!

If I want to include a dodgine mechanism, example the player presses "E" and when he does the player gets out of the way and even if a projectile touches him it "misses" and goes past him.
Would that be done with an if statement in a collision with the projectile?
Would I use an if statement in the object player and say if I press the "E" button getting hit by the projectile is false?

Ideas? I'm not the best at coding :/ Trying though! Thanks!
 
D

dawson2223

Guest
Code:
if !keyboard_check(ord("E"))
{
    // Your damage code here.
}
Basically, damage the player if you're not pressing "E".
I want to use a Dodge animation as well and don't want the player to be able to spam it. Can I do something similar to what you posted and still be able to do those things?
 

BeardyElf

Member
I have a dodging system in my game and basically I've done it as follow:
Game uses physics and bullets are flagged as sensors. When player dodges bullet, player instance changes to dodging player instance.
And bullet has a collision event with dodging player. When collision occurs, collision event checks if the players(other) image index is bigger than animation frame you want where the player is done dodging
and can take damage. And at the end of animation, instance changes back to normal player.
So to sum up. Player dodges bullet -> instance_change to dodging and plays dodging animation -> bullet collision event -> if image index in my case is less than 6, player dodges bullet (no special here, bullet continues as normal) ,
but if index is same or more than 6, player takes damage.
 
D

dawson2223

Guest
I have a dodging system in my game and basically I've done it as follow:
Game uses physics and bullets are flagged as sensors. When player dodges bullet, player instance changes to dodging player instance.
And bullet has a collision event with dodging player. When collision occurs, collision event checks if the players(other) image index is bigger than animation frame you want where the player is done dodging
and can take damage. And at the end of animation, instance changes back to normal player.
So to sum up. Player dodges bullet -> instance_change to dodging and plays dodging animation -> bullet collision event -> if image index in my case is less than 6, player dodges bullet (no special here, bullet continues as normal) ,
but if index is same or more than 6, player takes damage.
So would it be like,

Code:
if dodge = true
{
image_index = obj_dodgeanimation
     if image_index < 6
{
     No damage done?    // (I don't know how to code this)
else
{ player takes damage? }
}
}
 

BeardyElf

Member
Depends how you handle the dodging. Do you change player object to dodging player object or is it same object that plays just dodging animation?
Either way you need put code in bullets collision event for that object you use.
In my case is player dodging object. And when its created, it starts to play dodging animation.
And in bullets collision event for that object I have this:

Code:
if(other.image_index >= 6)
{
//my stuff here thats not relevant

        with(other)
        {
        physics_apply_impulse(x,y,other.ldx,other.ldy);
        global.player_hp[player_num] -= other.damage;
        }
  
    instance_destroy();
}
Code just checks if the animation is at the frame where primary dodge animation is finished, and if thats true player takes damage.

If you use only one player object, you could use variable dodge = true, when player is dodging and when the animation ends, change it back to dodge = false.
Then replace line if(other.image_index >= 6) with if(other.dodge == false) .
Sorry dont know better how to explain this.
 
D

dawson2223

Guest
Depends how you handle the dodging. Do you change player object to dodging player object or is it same object that plays just dodging animation?
Either way you need put code in bullets collision event for that object you use.
In my case is player dodging object. And when its created, it starts to play dodging animation.
And in bullets collision event for that object I have this:

Code:
if(other.image_index >= 6)
{
//my stuff here thats not relevant

        with(other)
        {
        physics_apply_impulse(x,y,other.ldx,other.ldy);
        global.player_hp[player_num] -= other.damage;
        }
 
    instance_destroy();
}
Code just checks if the animation is at the frame where primary dodge animation is finished, and if thats true player takes damage.

If you use only one player object, you could use variable dodge = true, when player is dodging and when the animation ends, change it back to dodge = false.
Then replace line if(other.image_index >= 6) with if(other.dodge == false) .
Sorry dont know better how to explain this.
Thanks for the reply! I'm going to sleep I'll check this out tomorrow.
 
D

dawson2223

Guest
Depends how you handle the dodging. Do you change player object to dodging player object or is it same object that plays just dodging animation?
Either way you need put code in bullets collision event for that object you use.
In my case is player dodging object. And when its created, it starts to play dodging animation.
And in bullets collision event for that object I have this:

Code:
if(other.image_index >= 6)
{
//my stuff here thats not relevant

        with(other)
        {
        physics_apply_impulse(x,y,other.ldx,other.ldy);
        global.player_hp[player_num] -= other.damage;
        }
 
    instance_destroy();
}
Code just checks if the animation is at the frame where primary dodge animation is finished, and if thats true player takes damage.

If you use only one player object, you could use variable dodge = true, when player is dodging and when the animation ends, change it back to dodge = false.
Then replace line if(other.image_index >= 6) with if(other.dodge == false) .
Sorry dont know better how to explain this.

Yeah I want it to be the same object just different animation.Okay that makes sense. How do I make it false after the animation is ran??
 
Top