PLATFORMER:Change behavour when overlap to Swim

0 favourites
From the Asset Store
Pathfinding AI
$2 USD
80% off
Units do not overlap each other and use different ways if there are several free ways.
  • EDIT: Well I was playing today with this challenge and came up with a solution thanks to few comments to give me the right idea.

    So heres one solution i came up with

    Example contains:

    -Basic description in eventsheet

    -Combination of two player sprites with platform and 8dirrection behavour

    -Immitation of swimming with jumping out effect

    -Very basic animation sprite effected by player movement

    File: dl.dropbox.com/u/5214903/GM/SwimmBehavour.zip

    ----------------------------------------------------------------------

    Hello

    What Id like to do is a platform game where by overlaping the water area, the players "Platform" behavour would change into "8direction" behavour to imitate swimming.

    The way I understanded it, is the Ignore input suposed to be used for what I plan.

    Problem:

    -Platform behavour wont jump

    -When overlaping the water area, player does change into 8 dirrection but sinks to the botom

    Illustrated Plan:

    <img src="http://dl.dropbox.com/u/5214903/GM/LetsGoSWIMM/swimmingPlan.jpg" border="0" />

    File:

    dl.dropbox.com/u/5214903/GM/LetsGoSWIMM/letsGoSwimm.zip

  • I have the same question actually, is behavior changing on runtime planned?

  • It isn't possible to change behaviors like that right now, but there's some workarounds to accomplish the same effect. One thing you can do is to not use the 8 directional movement at all, but to recreate that movement USING the platform behavior; set gravity to 0 so your character won't fall, and then have swimming-specific events that make you move in every direction upon key presses as if you were using 8direction.

    Another thing you can do is make the player invisible and spawn a new player, one that looks like the same but uses 8direction instead of platform. Then when you jump out of the water, destroy the water-player and make the normal platform player visible again.

    Neither one is ideal, but there may not be any other way to get it done. If you're still not clear on how to do it I could try to make an example for you. Hope this helps!

  • Thankyou very much for this example!

    It is definitely also a good way to create swimming behavour, allthough I noticed a glitch where the playier jumps out and remains in swimming mode while in air...

    The reason why I want to change the player from platform to 8 direction mode is to get more control in movement and not be influenced by things like gravity.

  • These are definitely good ideas to make what I have in mind.

    Ill definitely gonna try and examples would definitely be moust apreseated :)

    Thankyou

  • Made a new edit of this topic with new working example

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks Miu3, it will help and is really appreciate.

    What about a "jumping to dive" pose right before reach the water? I'll figure it out today, maybe using transparent objects to detect the water before he reach it.

    Thanks Kastas, your sample really help ^^

    While Diablo 3 don't come, let's make games xD

  • That's the only feature missing in my platform game.

  • This is a pretty old topic, but it's on the FAQ page and States are important, so...

    I make a Multi-State object by giving the object an Instance Variable which I call "State", which I set to a String. Make the default something like 'Walk' or 'Move'

    For your purposes, add both Platform and 8-Direction, but disable the 8-Direction to start.

    On the event sheet where you handle controlling your player, begin with the event "Compare Instance Variable" and see if it reads "Walk" Put all walking, running, standing on ground behaviors there. For your purposes, there you would use 'Set Enabled' to Enable Platform and Disable 8-Direction

    Next, when your player makes contact with the water, set 'State' to "Swim" and set it back to "Walk" when the player is not in contact with water (I think the 'Overlap' function would work there)

    Then, same thing, do a 'Compare Instance Variable' to see if State is "Swim", disable Platform and enable 8-Direction, then put in all your Swimming Behavior (such as changing animations to swimming, any swim-specific controls, even adding an Air Meter to the HUD if you'd like)

    It may seem a bit complicated, but that system (based off a Finite State Machine, if you want to look that up) is extremely powerful and makes for fairly clean code once you get used to it. You can use that same 'State' variable for climbing ladders, flinching on taking damage, and anything else that temporarily changes the behavior of your character.

    Hope that helps somebody!

  • psst! Hey, it would be even better if you add a actual example for the folks you know ;)

  • I just use the platform behavior to swim.

    I have a boolean called Swimming that sets to True when I'm overlapping water, and False when I'm not. When Swimming is True, I change gravity to 0 and mess with the Platform Behavior's vector-y. Left and right movement works the same as not in water, so I don't have to change that.

    One key thing I do is that I NEVER use the "jump" action at all in my game, I always just "set vector-y" to something (same effect as pressing jump). So when I'm in water and gravity is 0, pressing up sets vector-y to -250 and pressing down sets it to 250.

    Then I have one more event that triggers every 0.01 seconds that NEITHER up nor down are pressed in water: If vector-y is greater than zero, subtract 50, and if it's less than zero, add 50. That way, my character will slow down and stop when I let go of up or down.

    This method prevents me from having to add two movement behaviors to my character; I just don't like that.

    As an added bonus, I have a sprite indicating the top of the water. If my character is overlapping that and up is pressed, I set vector-y to -600 so that she pops out of the water. It's not necessary but I think it adds a really nice little touch.

    Here's a screenshot of the event sheet:

    <img src="http://img826.imageshack.us/img826/2023/49353921.png" border="0" />

  • MadameBerry

    i just had to say thank you!

  • On object clicked | add behaviour | scroll to

    8 direction

    bound to layout

    does that work somehow?

  • I just use the platform behavior to swim.

    I have a boolean called Swimming that sets to True when I'm overlapping water, and False when I'm not. When Swimming is True, I change gravity to 0 and mess with the Platform Behavior's vector-y. Left and right movement works the same as not in water, so I don't have to change that.

    One key thing I do is that I NEVER use the "jump" action at all in my game, I always just "set vector-y" to something (same effect as pressing jump). So when I'm in water and gravity is 0, pressing up sets vector-y to -250 and pressing down sets it to 250.

    Then I have one more event that triggers every 0.01 seconds that NEITHER up nor down are pressed in water: If vector-y is greater than zero, subtract 50, and if it's less than zero, add 50. That way, my character will slow down and stop when I let go of up or down.

    This method prevents me from having to add two movement behaviors to my character; I just don't like that.

    As an added bonus, I have a sprite indicating the top of the water. If my character is overlapping that and up is pressed, I set vector-y to -600 so that she pops out of the water. It's not necessary but I think it adds a really nice little touch.

    Here's a screenshot of the event sheet:

    Hi , please can you post an example capx of that?

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