Need help making shield follow player

T

ThatAussieKiwi

Guest
Hello,

I am trying to make a shield that spawns into the PlayerLayer when left mb is pressed and while left mb is pressed follow the player, basically mimicking player movement. But instead the shield stays in the same place where it was first spawned until left mb is released when the instance is destroyed.

My code:
if (mouse_check_button(mb_right)) {
if instance_exists(obj_PlayerSheild)
{
x = obj_PlayerShip.x;
y = obj_PlayerShip.y;
}
else {
instance_create_layer(x, y, "PlayerLayer", obj_PlayerSheild);
}
}
if (mouse_check_button(mb_right) = false) {
instance_destroy(obj_PlayerSheild);
}

Once again, thank you for all your help!
 

Plisken

Member
Which object is this code in? is it in the player object or the shield object?

If the code is in the ship object, then it might be because where it says:

x = playership.x
y = playership.y

it should say something like:

obj_shield.x = x
obj_shield.y = y
 
T

ThatAussieKiwi

Guest
Which object is this code in? is it in the player object or the shield object?

If the code is in the ship object, then it might be because where it says:

x = playership.x
y = playership.y

it should say something like:

obj_shield.x = x
obj_shield.y = y
It is in the ship code
 
T

ThatAussieKiwi

Guest
Which object is this code in? is it in the player object or the shield object?

If the code is in the ship object, then it might be because where it says:

x = playership.x
y = playership.y

it should say something like:

obj_shield.x = x
obj_shield.y = y
Would
obj_PlayerShip.x = obj_PlayerSheild.x
work?
 
T

ThatAussieKiwi

Guest
Try this. erase that code, then go to the step event of the shield object, and type:

x = obj_playership.x
y = obj_playership.y

place the object in the room and run it and see what happens.
That did the job perfectly, i only had to add
direction = point_direction(x, y, mouse_x,mouse_y);
so that the shield rotated with the ship
 
T

ThatAussieKiwi

Guest
Thanks for your help!
 
Last edited by a moderator:

Plisken

Member
Do you know how i can make it so the shield(right mb) cannot be active while shooting(left mb) and vice versa?
Try this: in the shield objects begin step event, check if the left button is pressed, if it is then destroy it.

The begin step event checks stuff before the main step event. So I think that might work.

You could also check if the left button is pressed in the right mouse event and if it is then exit.
 
T

ThatAussieKiwi

Guest
Try this: in the shield objects begin step event, check if the left button is pressed, if it is then destroy it.

The begin step event checks stuff before the main step event. So I think that might work.

You could also check if the left button is pressed in the right mouse event and if it is then exit.
I tried just saying if left mb is pressed and right mb is false the shoot
 
Top