Weapon switch

0 favourites
From the Asset Store
Toggles Dials Switches and Alerts ! A foundational sound grouping of Analog type switches and Steampunk effects
  • Hi, I have what I see as a complex problem...

    I have a few weapons for the player in the game. I want the player to be able to hold 2 weapons at a time and switch between them when pressing a key. When the player goes to a shop and buys a weapon the weapon should replace the current 'active' weapon.

    I am not asking you to do the whole event sheet, but some examples or perhaps directions on where to begin would be appreciated.

  • i'm sure someone will 'help' you. but i would like to suggest that what i do when i start working on game logic, is make bullet statements, or short sentences. if you can break down what you wan to do into short statements, it will almost literally tell you how to build/write the events for it.

    i only mention it because, as i was reading your thread, i could see the events in each sentence you wrote.

    good luck...

  • i did something similar, but i'm not sure if my solution is perfect.

    i looked at the weapons as numbers.

    1 = first weapon

    2 = second ......

    3 = third .....

    if the next weapon is selected a variable called "current" would increment by one. selecting the previous weapon would decrement "current".

    if the player would press the key to use the weapon it would check the value of "current" and if it is 2 the shot of the second weapon would be fired and so on.

    i hope this helps you a bit.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks, guys, epecially Pete... I know where to start now.

    So i'm thinking this: each weapon has a 'value'.

    So if current_weapon = 1 then delete the current weapon and place Weapon 1.

    I think i will need to store another variable second_weapon. When the key is pressed to switch, the values of these variables swap.

    To destroy the weapons I have a condition system global variable if current_weapon does not equal (1, for example) then for turret1 play animation put away then destroy the instance.

    To create the instance i would want it to wait until the animation 'put away' of the gun is finished before the 'take out' starts. I am not sure how to handle this. Any ideas?

  • You could also do all weapons as a animations in one sprite. Then instead of deleting instances and creating new ones you can just switch animations :)

  • Hmm, even if the weapons are significantly different from each other in terms of what they shoot?

    Interesting, but with supplementary animations for going to and from each weapon, I think this would add more complexity than simplicity.

  • Hmm, even if the weapons are significantly different from each other in terms of what they shoot?

    Sure - you'd just have subevents, like this (indented means subevent):

    + On shoot

    ----+ Current weapon is pistol

    ----> Shoot bullet

    ----+ Current weapon is grenade

    ----> Shoot grenade

    ----> Current weapon is rocket launcher

    ----> Shoot rocket

    etc.

    Having separate objects for player and their weapon sounds like a good way to do it - otherwise you have to redraw your player's animations (walking, running, jumping etc.) once for each weapon.

  • How weapon shoot is usually defined by variables.

    +If var "weapon" = 1

    • set animation to "weapon1"
    • set "fire_speed" = 5

    etc.

    and for switching   

    If animation "put away" finished -> set animation to "weapon2"

    just an example :)

  • This looks very interesting... I think I will give your method a try!

    By the way, does anyone know a simple and efficient way using as less events as possible to establish a fire rate for a weapon?

  • OK I have it all working and followed your advice, EXCEPT for the put-away and take-out animations for each weapon. I am a bit lost as to what to do for these. I have these animations as animations within the main weapon object but they are not used by the program as of yet.

    Any advice as to how I can implement this feature?

    Much thanks for all your help :)

  • could you post your project or screenshot from your event editor? that would help us to help you :)

  • OK, Here is my event sheet. It will probably help to know that it is a top down tank game. The other weapons are further below but follow the same model as 'turret_basic'.

    <img src="http://i681.photobucket.com/albums/vv179/sqiddster/Eventsheet.jpg" border="0" />

    What I need is a way to integrate the 'put away' and 'take out' animations efficiently.

  • I have solved this problem thanks no a nice session in the chat. Thank you for all suggestions guys!

  • Hi guys, I'm trying to make a sidescrolling shooter, but I'm stuck with the weapon system. I've got 4 different weapons and the sprites are organized in that way:

    • main character (it has 2 sets of animations: run body, idle body);
    • weapon A, B, C, D (each has 3 set of animation: idle, run, fire);
    • unharmed arm complementary to single handed weapons;
    • explosion (the flame burst from the weapon, a small animation).

    I've done my best to organize the .capx, but I'm getting real crazy 'cos:

    • the one shot weapons are supposed to shot once for every time you push the button;
    • the autofire weapon are supposed to shot continously till you hold down the fire button;

    My problem is that nothing works actually :( and I when something start working the animations when a condition change don't mach (ex: if weapon is firing and it stops while moving, it will not be on "run" again).

    Anyway, here we have the .capx file.

    dl.dropbox.com/u/42804939/help.capx

    Could you help me in making some exemple capx or tutorial? Thank you so much guys!!!

  • Wow, this is an old thread!

    Anyway, happy to help. I can't access the capx file now however (not at home) ... I may in a few hours.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)