I have tried to set up something like this by creating the variable playerlocation. If it is equal to 0 the player should be able to move around as the player and if it is equal to 1 the player should move around as the tank, but instead when the player goes up to the tank and presses E they go into the tank but the tank wont move. I have tried a few different things but if one part works, another part wont work. Here is my code. Thanks for the help.
obj_tank-create
depth = 0;
playerlocation = 0;
allow = 1;
shoot = 0;
reload = 90;
up = 0;
tankbulletspeed = 12;
length = 37;
image_speed = 0;
obj_tank-step
if (playerlocation = 1)
{
sh = mouse_check_button_pressed(mb_left);
if (allow = 1)
{
pointdir = point_direction(x,y,mouse_x,mouse_y);
image_angle += sin(degtorad(pointdir-image_angle))*3
if (shoot == 0)
{
up += 1;
if (up >= reload)
{
shoot = 1;
}
}
if sh
{
if (shoot == 1)
{
sprite_index = spr_tankturretfire;
shoot = 0;
up = 0;
tankbullet = instance_create_layer(x + lengthdir_x(length,image_angle),y + lengthdir_y(length, image_angle),"Bullets",obj_tankbullet)
tankbullet.direction = image_angle;
tankbullet.speed = tankbulletspeed;
}
} else
{
sprite_index = spr_tankturret;
}
}
//End for Playerlocation
}
if (playerlocation = 1)
{
sh = mouse_check_button_pressed(mb_left);
if (allow = 1)
{
pointdir = point_direction(x,y,mouse_x,mouse_y);
image_angle += sin(degtorad(pointdir-image_angle))*3
if (shoot == 0)
{
up += 1;
if (up >= reload)
{
shoot = 1;
}
}
if sh
{
if (shoot == 1)
{
sprite_index = spr_tankturretfire;
shoot = 0;
up = 0;
tankbullet = instance_create_layer(x + lengthdir_x(length,image_angle),y + lengthdir_y(length, image_angle),"Bullets",obj_tankbullet)
tankbullet.direction = image_angle;
tankbullet.speed = tankbulletspeed;
}
} else
{
sprite_index = spr_tankturret;
}
}
//End for Playerlocation
}
obj_player-create
depth = 100;
playerlocation = 0;
playerspeed = 2.5;
hp = 3;
cooldown = 0;
collisionspeed = playerspeed + 2;
obj_player-step
//Player starts by controlling the player
if (playerlocation = 0)
{
//Movement
if (keyboard_check(ord("W"))) and place_free(x, y-collisionspeed)
{
y = y-playerspeed;
}
if (keyboard_check(ord("S"))) and place_free(x,y+collisionspeed)
{
y = y+playerspeed;
}
if (keyboard_check(ord("D"))) and place_free(x+collisionspeed,y)
{
x = x+playerspeed;
}
if (keyboard_check(ord("A"))) and place_free(x-collisionspeed,y)
{
x = x-playerspeed;
}
//Shooting
if (mouse_check_button(mb_left)) and (cooldown < 1)
{
instance_create_layer(x,y,layer,obj_bulletplayer);
cooldown = 100;
}
cooldown = cooldown - 1;
//Death
if (hp <= 0)
{
game_restart();
}
//end for playerlocation
}