RPG selecting system

SkyMapleSkyMaple Member Posts: 817
edited November -1 in Working with GS (Mac)
I started making an rpg but I'm faced with a problem. In most games your player has to be facing an object to select it for various actions. How can I do this without being able to select an object when the player is facing away from it?

Comments

  • SlickZeroSlickZero Houston, TexasMember, Sous Chef Posts: 2,870
    Hopefully, you have attributes that tell if you are facing left or right...

    Make an attribute "Interact"
    If attribute "facing left" = "true" and attribute "facing right" = "false" set attribute "interact" to 0
    If attribute "facing right" = "true" and attribute "facing left" = "false" set attribute "interact" to 1

    On the object to be interacted with...

    (If colliding or if magnitude is met...or whatever you have for interaction with the object) and attribute "interact" = 1 destroy this actor/spawn actor/ set attribute "bullet count" to "bullet count"+100...etc...
    If attribute "interact" = 0 then do nothing
  • PhoticsPhotics Member Posts: 4,172
    SkyMaple said:
    I started making an rpg but I'm faced with a problem. In most games your player has to be facing an object to select it for various actions. How can I do this without being able to select an object when the player is facing away from it?

    You could also constrain an invisible actor to the main hero... the actor would stick out a little bit ahead of the main actor.

    If overlaps or collides with "line of sight"
    and overlaps or collides with "Hero"
    Then... run behaviors

    The position of the "Line of Sight" actor would be constrained using cos and sin.
  • SkyMapleSkyMaple Member Posts: 817
    SlickZero said:
    Hopefully, you have attributes that tell if you are facing left or right...

    Make an attribute "Interact"
    If attribute "facing left" = "true" and attribute "facing right" = "false" set attribute "interact" to 0
    If attribute "facing right" = "true" and attribute "facing left" = "false" set attribute "interact" to 1

    On the object to be interacted with...

    (If colliding or if magnitude is met...or whatever you have for interaction with the object) and attribute "interact" = 1 destroy this actor/spawn actor/ set attribute "bullet count" to "bullet count"+100...etc...
    If attribute "interact" = 0 then do nothing

    Oh, I just got an idea! what I had been doing before is trying the set up a line of sight like photics said but I couldnt get it to stay in the right place. It was very frustrating! Instead what I will do is have the player spawn a "bullet" type actor that accelerates toward the item i want to select. I will have it so after about .2 seconds it will be destroyed or recycled but when it collides with item do an action.

    @photics if you could give me some code for your idea that would be awesome! :D
  • PhoticsPhotics Member Posts: 4,172
    SkyMaple said:
    @photics if you could give me some code for this that would be awesome! :D

    The Math section from The Unofficial GameSalad Textbook could be very helpful for stuff like this.

    Basically... it involves aligning your actor (and image) to the 0° angle, and using a circle

    (cos( game.HERO-Rotation)*12)+ game.HERO.X
    (sin( game.HERO-Rotation)*12)+ game.HERO.Y

    ...but that's like five constraints...

    three for the hero and two for the line of sight.

    ...maybe three if you constrain the line of sight actor's rotation to the same angle as the hero's angle.
  • SkyMapleSkyMaple Member Posts: 817
    Photics said:
    The Math section from The Unofficial GameSalad Textbook could be very helpful for stuff like this.

    Basically... it involves aligning your actor (and image) to the 0° angle, and using a circle

    (cos( game.HERO-Rotation)*12)+ game.HERO.X
    (sin( game.HERO-Rotation)*12)+ game.HERO.Y

    ...but that's like five constraints...

    three for the hero and two for the line of sight.

    ...maybe three if you constrain the line of sight actor's rotation to the same angle as the hero's angle.

    I added this to my line of sight actor but how can I set the offset for the line of sight being in front of the hero?
  • PhoticsPhotics Member Posts: 4,172
    That's what the number "12" is about. Did you try increasing the value?
  • SkyMapleSkyMaple Member Posts: 817
    Photics said:
    That's what the number "12" is about. Did you try increasing the value?

    I changed it to +40 and this is what I got ;/

  • PhoticsPhotics Member Posts: 4,172
    I can't see your code in the video.

    I'm thinking you might have have mixed something.

    Heh, looks like the start of a fun game though.
  • SkyMapleSkyMaple Member Posts: 817
    image

    Heres the code. And thanks! This is the beginning of an RPG.

    EDIT: Its small on here, just open the image in a new tab.
  • PhoticsPhotics Member Posts: 4,172
    On the cos/X Constrain, you put 0 instead of 60.
  • SkyMapleSkyMaple Member Posts: 817
    Photics said:
    On the cos/X Constrain, you put 0 instead of 60.

    Yep, thats so that it stays in the middle. If I put 60 it would offset it.

    Is there something I need to add to the rotation?

    I dont know. Its supposed to rotate around the hero when he moves. right now it just stays in the same place.
  • SkyMapleSkyMaple Member Posts: 817
    could you make a demo?
  • PhoticsPhotics Member Posts: 4,172
    It doesn't have to stay in the middle. It's line of site. It just has to stick out a little — in the direction the character is looking. Your rule covers the rest.

    If overlaps/collides with line of site
    AND overlaps/collides with hero
    Then... run behaviors
  • SkyMapleSkyMaple Member Posts: 817
    Photics said:
    It doesn't have to stay in the middle. It's line of site. It just has to stick out a little — in the direction the character is looking. Your rule covers the rest.

    If overlaps/collides with line of site
    AND overlaps/collides with hero
    Then... run behaviors

    If you saw the video you would see that it doesn't work properly. and what I meant by stay in the middle was I need the X axis to stay centered but the Y axis to be offset so to be in front of the hero.
Sign In or Register to comment.