J
Jane Landrum
Guest
Hey guys! The title is pretty straightforward, I just want to be able to only read signs and stuff when I'm standing in front of it and the sprite is facing towards it, instead of just colliding with it anywhere. Any tips?
if (((x < other.x) && (other.facing = -1)) || ((x > other.x) && (other.facing = 1))) { // if ((sign is on the left side of the player AND the player is facing left) OR (sign is on the right side of the player AND the player is facing right))
// draw the text
}
if instance_exists(obj_player)
{
depth = obj_player.depth-1
dir = (obj_player.dir)
if (dir = 0)
{
x = obj_player.x + 32
y = obj_player.y
image_speed=0; sprite_index=spr_target_box // right
}
else
if (dir = 1)
{
x = obj_player.x
y = obj_player.y + 32
image_speed=0; sprite_index=spr_target_box // down
}
else
if (dir = 2)
{
x = obj_player.x - 32
y = obj_player.y
image_speed=0; sprite_index=spr_target_box // left
}
else
if (dir = 3)
{
x = obj_player.x
y = obj_player.y - 32
image_speed=0; sprite_index=spr_target_box // up
}
}
I need a little help integrating it into my code if you don't mind. First of all I probably should've mentioned that my game isn't a side scroller (like Terraria or Shovel Knight or any of those games), it's more like Undertale or Stardew Valley where you can walk up and down and there's depth to it. I want to be able to stand in front of the sign to read it instead of to the left or right. Sorry about that I should have clarified in the first place!Check the coordinates and direction.
Sign collision event with player
Set the player's facing variable according to the appropriate movement code.Code:if (((x < other.x) && (other.facing = -1)) || ((x > other.x) && (other.facing = 1))) { // if ((sign is on the left side of the player AND the player is facing left) OR (sign is on the right side of the player AND the player is facing right)) // draw the text }
Hope I helped
Not quite sure as I never tested this, but I think adding a check on the y axis should deal with up and down movements.I need a little help integrating it into my code if you don't mind. First of all I probably should've mentioned that my game isn't a side scroller (like Terraria or Shovel Knight or any of those games), it's more like Undertale or Stardew Valley where you can walk up and down and there's depth to it. I want to be able to stand in front of the sign to read it instead of to the left or right. Sorry about that I should have clarified in the first place!
The way I have everything set up is with a parent (oParentTalk) that is the parent of all the signs or anything I will need to interact with (NPCs, etc.). I already have it drawing all the text in the Step event, so should I copy and paste all of the step event into the collision event? Or should I put this code into the Step event? Or is there a way to say "go to the step event" that I could put in the collision event within the if statement? Sorry for the confusion.
if (((x < other.x) && (other.facing == "-1")) || ((x > other.x) && (other.facing == "1")) // handle x axis, -1 is left and 1 is right
|| ((y < other.y) && (other.facing == "-i")) || ((y > other.y) && (other.facing == "i"))) { // handle y axis, -i is up and i is down
// draw the text
}
So how I do player facing is I have 4 different sprites for walking up, down, left, and right. Then in the player step event I have it to where the image_speed is movement speed/3..so if the movement speed is 0 then the image speed is 0 and it just stops on frame 0 which is the one that just faces that direction.Not quite sure as I never tested this, but I think adding a check on the y axis should deal with up and down movements.
Hope I helpedCode:if (((x < other.x) && (other.facing == "-1")) || ((x > other.x) && (other.facing == "1")) // handle x axis, -1 is left and 1 is right || ((y < other.y) && (other.facing == "-i")) || ((y > other.y) && (other.facing == "i"))) { // handle y axis, -i is up and i is down // draw the text }
facing = "1"; // because the default angle and thus direction is right
if (keyboard_check(ord("W")) {
// or whatever your movement code is
facing ="-i";
}
... do the same for all the other directions
if (facing == "1") {
sprite_index = player_facing_right_sprite;
} else if ... do the same for all the other directions
The variable facing belongs to the player, not the sign, in case you got it mistaken.I was a little confused about what to do with the variable 'facing' that's used in the code above.
// the code in previous reply
All drawing should be handled in the draw event, no exceptions at all. Otherwise it won't be drawn at all.because I'm already drawing the text in a step event