How do I switch between two modes/controls and back?

0 favourites
  • 5 posts
From the Asset Store
Helping streamers give their viewers more excitement.
  • Hello all! So I'm experimenting and trying to code a scene where you control a side scrolling character and you're able to board and pilot a physics based space ship. I have decent side scroller controls and now I'm beginning to implement some space ship controls. I'm able to "switch" and control the space ship but I can't switch back. The "F" button is a context sensitive button/action so if you're near a switch, near you're ship, near another player, etc, the "F" button will engage some sort of gameplay element/function. In this case, I'm just boarding and unboarding a space ship, switching "characters" or control states, if you will. Hope this is a clear explanation for my question. How would I go about switching on the fly my two modes of play, ground and air?

    In the final version, I'd want the player near the ship in order to "board" and control it. I'd like the player to only be able to disembark by a context sensitive action/landing animation when close enough to the ground. Right now though, I'd just like to switch back and forth between the ship and character, from where I left last either one. Here's my code and a gif. I'm new to construct 2. I tried having the space ship code in the same event sheet and a separate one, it makes not difference. Maybe I'm having trouble linking them? Should overall "controls" of any and all characters/vehicles/etc be under the same event sheet? I'm not sure my event sheet management is very good. Thanks for looking at my questions folks!

    edit: Deleted my original question over at the main "How do I....? thread. My topic title had a very beginner sounding title compared to the others so thought it probably belonged here.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ok, don't know what I did but I fixed it. Eventually it crashed though and now I'm not able to get the exact code back in there to make it work. I'd really appreciate any help or suggestions on how to approach this.

    It was working as intended, I could switch back and forth and pick off from where I last left the character or vehicle but the crash killed all that. Here's some of what I did to get it working. I moved the "Context Action System" group outside of the "Ground Control" group. I also created an instance variable for the ship called "state" and number it "0". "0" means off/idle, "1" means activated/controlled. If the player presses F and the ships "state" = 1, basically control would return back to the ground character and set "state" = 0. I guess I did some other important things because I can't get the results again.

    Here's the code. Right now it's broken, it just turns my ground character invisible but it's close to how the code was looking while working earlier. If I remove that bottom block of code, I'm able to switch to the ship again. Thanks!

  • Your problem is simple let me explain

    Using an on keyboard command or any kind of input will trigger everything that has that particular input in your event sheet so pressing F will trigger all of your on keyboard F inputs so your first one triggers first making your second condition true before it runs because constructs order of operation is top-down your second F input will always be true

    Good luck with your project if you need help feel free to contact me through private message and we can talk on Skype, email, or steam I can help with any questions you have.

  • Thanks Brandon. I got it working! I really need to go through more of the online documentation. I found this https://www.scirra.com/tutorials/158/ve ... two-states and it really helped me see what I did wrong. Yeah, my order of operations were screwy! Thanks for pointing that out, it's really going to help me going forward. And thanks for your offer! I'll definitely message you!

    I'm wondering, should the player character controls and space ship controls have their own separate event sheets or share one? Does it matter?

    So the code is fixed...for now. The player can switch to the ship at any time. The ship can only land and switch back to the player when the "ShipLander"(a small box that tests if the ship is close enough to a solid surface to land) underneath it collides with tilemap. Now I guess I should modify the code so that it takes into consideration how close the player is the the ship. The player has to be close enough to perform a climbing animation to enter the ship. Also I guess this specific code should also include events that "pick up" and "drop off" the player around the game level. Anyway, here's the code for anyone who's curios and for future generations!

  • so it's really up to you how you want to set up your code but if you going to have a game with many different vehicles I'd recommend setting up controls for each one individually if they all have different movement mechanics. You are definitely on the right track with your state system. There's a few ways of doing it that different people use.

    Some people do all of their code for that vehicle under each state as a sub event http://puu.sh/pTM5Q/bfa7f69faa.png

    I prefer using something similar to this http://puu.sh/pTMsX/bb451fbf65.png

    And if you need something to happen when a state's gets activated just use http://puu.sh/pTNa5/2264f15539.png

    Both ways work so it's really up to you and in both these examples you can have way more than just the movement code under your States and of course there a ton of ways to do this so find the one that works best for your project Good luck <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy">

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