Weapon Selection help please?

allc1865allc1865 Member, PRO Posts: 777
Hey everyone. I'm trying to create a weapon selections where I can select the kind of weapons I want. I've tried watching GSHelper's multi weapon selections, but I'm using a joystick and so I think that's where it went wrong because it doesn't work, and by that meaning, when I shoot, it only shoots in one direction and in a small little pile next to my player. Not what I wanted.
Any help would be great! Thanks you! :)

Best Answers

  • ZeroRavenZeroRaven Posts: 33
    Accepted Answer
    allc, I've used multiple weapons like this before. How did you want to switch weapons forst off?
    When I did it I used the 1,2,3,4 keys and had each tied to a game attribute.
    so
    When:
    Key (1) is pressed
    Do:
    Change attribute (game.weapon1) to true
    Change attribute (game.weapon2) to false
    etc.

    So when you press your fire button it should have a code to check which weapon is selected.
    When:
    Key (trigger?) is pressed
    Do:
    If attribute (game.weapon1) is true,
    spawn selected actor.

    This way you can have each weapon have different properties.
    You'd wanna make sure though that you have code is the initial weapons selection to DESELECT the other weapons.

    Hope this helped.
  • tatiangtatiang Posts: 11,949
    Accepted Answer
    Constrain a gun actor to the tank actor so that its x/y position is constrained to the x/y of the tank. Do not put the constrain behavior inside of a rule.

    Change the image and rules according to a game attribute such as game.weaponChoice.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Posts: 11,949
    Accepted Answer
    @allc1865 You're welcome!

    Pro members can upload a .zip file or other attachment to the forums. Anyone can post a link to a hosted file.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Answers

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    It sounds like you're having a problem with shooting bullets, not with weapons selection.

    What behavior are you using on the bullet actor(s) to move them? If you spawn a bullet actor, it won't automatically go anywhere. You have to use something like a Move behavior to move it across the screen. Set the direction to 0 or 90 relative to actor (it depends on the size of your actor, so try both).

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • allc1865allc1865 Member, PRO Posts: 777
    I'm using a joystick and the way I have it is that when you go to shoot, you can shoot 360 degrees, not just one straight path. I'm also using the Spawn actor to spawn my bullet.

    I've got it working this way -- I'm not sure if this is the best way, but I'm using true or false statements to get a different bullet to shoot out.
    So basically, the button that you press to get a different bullet to shoot out says, when touch is pressed > change attribute game.weaponAmmo to true.
    In the bullet actor I have it saying, when attribute game.weaponAmmo is true > change image.
    It seems to work this way...
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    There are two issues here and I think we should deal with them separately: (1) How to choose a weapon and have the correct bullet be spawned and (2) How to have a bullet move in the direction your character or gun is facing.

    I was referring to #2 and wondering how you're having the bullet move...? Maybe you can post a screenshot of your Spawn rule and your bullet rules/behaviors so we don't go 'round in circles.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • allc1865allc1865 Member, PRO Posts: 777
    @tatiang,
    these are the rules for my bullets in my player actor:

    image

    these are my rules for my bullet actor:
    Note: The rules that says "when weaponAmmo is true change image", that is what I recently added to make my bullet change when a button is pressed. I wasn't sure if you wanted to see that or not.
    image

    Thanks for your help.
  • allc1865allc1865 Member, PRO Posts: 777
    @ZeroRaven, Okay. I see what you did. Seems easy enough. Just have an attribute that says when bullet 1 is selected, turn your original bullet off.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Hmm... looks pretty good to me. Although I notice that you have the direction for the spawned bullet set to a game attribute with relative to actor selected. It's possible that needs to be relative to scene.

    As far as the bullet movement goes, did you experiment with 90 degrees as well as 0 degrees? If you want to send me a link to download your project file, I may have more luck if I see how you have it all set up.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • allc1865allc1865 Member, PRO Posts: 777
    @tatiang, changed it to relative to scene. If you wouldn't mind taking a look at my file, that's be great! Thanks! :) ;)
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    https://www.dropbox.com/s/tu1p51ive88oxkk/mygreatgame.zip :)
    It seems like you have the bullets firing correctly. Is there something you're still wanting help with?

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • allc1865allc1865 Member, PRO Posts: 777
    Yes, two things please if you wouldn't mind helping me with. One off topic, the other one I think would match this thread.

    I guess I'll just start off with the second one. If I wanted to have a particular gun or so attached to my actor when button is pressed, how would I do that? When touch is pressed constrain attribute gun to player?
    Thanks for all your help!
  • allc1865allc1865 Member, PRO Posts: 777
    So in the gun actor I would put constrain attribute > self.x to playerx and constrain sttribute self.y to playery?
    Thanks for your reply, @tatiang
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @allc1865 Yes.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • allc1865allc1865 Member, PRO Posts: 777
    @tatiang, I'm sorry. How do I make it rotate to actors position?
  • allc1865allc1865 Member, PRO Posts: 777
    That is, to make the gun go in the same direction as the actor player.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited December 2013
    Here's a demo. Note that I borrowed a graphic from http://opengameart.org and placed it on a transparent background twice its height so that the center of the turret was in the center of the background and then exported it as a png.

    In the demo, you use the arrow keys to move and rotate the tank body. The A and S keys rotate the turret and the space bar fires a bullet.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    That is, to make the gun go in the same direction as the actor player.
    So you want the gun to always point in the same direction, rather than swiveling independently, as in my demo? If so, just constrain the self.rotation of the gun to the self.rotation of the player.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • allc1865allc1865 Member, PRO Posts: 777
    Thanks so much for the templates! They help out a lot!

    Let me ask. What do you mean by "Change the image and rules according to a game attribute such as game.weaponChoice"?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    In the actor that allows you to select a weapon, have a rule that changes game.weaponChoice (an integer) to some value. So machine gun might be 2 for example.

    In the turret/gun actor, have a rule that says When attribute game.weaponChoice=2 ... Change whatever attributes you want to be affected, such as rotate speed, spawn rate, etc. Do the same thing in the bullet actor so that it's speed or damage or whatever are also affected by the value of game.weaponChoice.

    Then if you want a flamethrower, it could be game.weaponChoice=3 with rules for that value.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • allc1865allc1865 Member, PRO Posts: 777
    Okay, that's good. Thank you so much for all your help! ;) :)

    If you don't mind me asking, how do you get your project file that you've zipped to show up on the webpage instead of posting a link?
  • allc1865allc1865 Member, PRO Posts: 777
    Okay, thanks. PRO is a pretty cool feature then. :) ;)

    @tatiang
Sign In or Register to comment.