Difficulties creating a ghost dash

Basically I am trying to replicate a ghost dash from another tutorial. The difference is that in the other tutorial he was actually teleporting the object to mouse_x and mouse_y and therefore it's easy to call for the x and y positions of the mouse when creating the path for the dash. In my case I will be using "w","a","s","d" to move the player. I have hsp and vsp to set my horizontal and vertical speeds. I have 2 major issues. the first is that the game is crashing moments after pressing "shift". The second is that I am not sure how to add the second positions of x and y (player position after dashing) whilst creating the path. I tried substituting x with x+hsp and y with y+vsp. This is the code I m using:

// dash
if(keyboard_check_released(vk_shift) and global.mana >=30)
{
alarm[0] = 10;
global.mana = global.mana - 30;
grv = 0
walksp += 10
if (walksp >= 100) walksp = 100

//create path
var dashPath = path_add();
path_set_closed(dashPath, false);
path_add_point(dashPath,x,y,0);
path_add_point(dashPath, x+hsp, y+vsp, 0);

//Distance
var distance = round(point_distance(x,y,x+hsp,y+vsp))

//Amount of Ghosts
var ghostsToMake = ceil(distance/sprite_width);

for(var i= .96; i>=0;i-=.9/ghostsToMake) {

var ghost = instance_create_depth(path_get_x(dashPath, i), path_get_y(dashPath,i), depth, obj_player_dash);
ghost.image_alpha = i;

}

//move player
x = x+hsp
y = y+vsp

//destroy path
path_delete(dashPath);
}
 

SeraphSword

Member
A couple things:
  • If you're getting a crash, it would be useful to let us know what the crash message says
  • You're creating a path, but I don't see path_start anywhere. I don't mess with paths too much, but I think that's necessary.
  • Why not just use the teleport code from the tutorial you are following, and use your (x+hsp, y+vsp) as the target destination instead of (mouse_x, mouse_y)?
  • One other thing I'm not sure of is creating a path as a local variable. This might be possible, but it seems dangerous to me.
 
Top