M
Mr. Nice Shirt
Guest
Hello there! I am currently working on a side scrolling platform game with a main focus being hookshot based grappling which the player will use to both traverse and fight/grab enemies using a button press based on the direction the player is facing similar to say 2D Zelda.
Currently, I am able to shoot out the ‘hookshot’ object instance and have the x and y of the origin saved(where it was created). When it hits a wall object, it continues to move, but slows down instead of returning to the player. This is as far as I have gotten. I still need a way to check on the hookshot’s step event when it has reached a certain distance from where it was created, check for collisions it can interact with on each step and if a hookshot object is already out, when a collision is found or the distance of the rope is reached without collision, pull it back. I also need to create two different “pull it back” functions/scripts based on the type of collision (Pulling the player towards an object, or pulling the object towards the player.)
Now here is my code so far:
Player's Step Event:
Hookshot's Create Event:
Hookshot's Step Event:
Thank you for your time!
Currently, I am able to shoot out the ‘hookshot’ object instance and have the x and y of the origin saved(where it was created). When it hits a wall object, it continues to move, but slows down instead of returning to the player. This is as far as I have gotten. I still need a way to check on the hookshot’s step event when it has reached a certain distance from where it was created, check for collisions it can interact with on each step and if a hookshot object is already out, when a collision is found or the distance of the rope is reached without collision, pull it back. I also need to create two different “pull it back” functions/scripts based on the type of collision (Pulling the player towards an object, or pulling the object towards the player.)
Now here is my code so far:
Player's Step Event:
Code:
//Imput
key_left = keyboard_check(ord("A")) || keyboard_check(vk_left);
key_right = keyboard_check(ord("D")) || keyboard_check(vk_right);
key_jump = keyboard_check_pressed(ord("W")) || keyboard_check(vk_up);
hook = keyboard_check_pressed((vk_space));
//Caluate movement
var move = key_right - key_left;
hsp = move * walksp;
vsp = vsp + grv;
if (place_meeting(x,y+1,owall)) && (key_jump)
{
vsp = -7;
}
//Horizontal collision
if (place_meeting(x+hsp,y,owall))
{
while (!place_meeting(x+sign(hsp),y,owall))
{
x = x + sign(hsp);
}
hsp = 0;
}
x = x + hsp;
//Vertical collision
if (place_meeting(x,y+vsp,owall))
{
while (!place_meeting(x,y+sign(vsp),owall))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;
//Hookshot
if (hook == true){
var hooky = instance_create_layer(x + lengthdir_x(64, image_angle),y + lengthdir_y(64, image_angle), "Instances_1",ohookshot);
hooky.direction=0;
hooky.speed=7;
if(image_xscale == 1){hooky.direction=0;}
if(image_xscale == -1){hooky.direction=180;}
}
Code:
hsp= 7;
go_back = false;
control = true
//this is where the x and y are saved
x = oplayer.x;
y = oplayer.y;
var i = 0;
with (ohookshot) {
saved_x_array[i] = x;
saved_y_array[i] = y;
i += 1;
}
Code:
if(instance_exists(oplayer)) {
if((lengthdir_x < 100)) {
speed = -25;
}
}
if (collision_rectangle(bbox_left-1,bbox_top,bbox_right+1,bbox_bottom,owall,true,false))
{
//hsp = -hsp;
hsp = 0;
go_back = true;
}
if (go_back)
{
move_towards_point(x, y, oplayer)
}
if (oplayer.hook)
{
if (place_meeting(x,y,oplayer))
{
oplayer.hook = false;
instance_destroy();
}
}
x += hsp;
Last edited by a moderator: