GML Help making Enemy Knockback/Script

Powerset

Member
Hello! So I got some Enemy knockback working for my game. The only problem is im trying to transfer the logic into a script and im hitting major roadblocks. I cant seem to figure out whichever part of it im doing wrong. Inside the enemy hurt state I have this:
Code:
case ENEMYSTATES.HURT: {

    sprite_index = sEnemy;

  
    image_speed = 1;

    
    hsp = Approach(hsp, 2, 0.3);
    
    vsp -= 4;
    
    }
Its pretty basic and works as intended as by pushing the enemy back, the only problem is that its hard coded. I'm trying to create a script where I could easily change the variables of the height and the distance depending on the different attacks. So for my Knockback Script to be something like this:

Code:
function Knockback(_knockback, _knockbackHeight){
        

}
The approach script doesn't work because its not doing it gradually in the step event. Should I be using GMS2 built in "x" and "y" inside the script? How should I go about this script exactly in pushing my Enemy back? Im pretty confused and the only thing I keep seeming to do is hard code this stuff. Any insight to this?
 

Nidoking

Member
I'm confused about your confusion, frankly. What do you mean by "its not doing it gradually in the step event"? What are you doing that is not exactly these steps:
  1. Add a function declaration in a script.
  2. Copy the code you want to be in the function into the function.
  3. Replace the hardcoded values with the function parameters.
  4. Replace the code you copied with a call to the function.
Next, if you've decided to deviate from the above steps... why?
 
Top