Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: (help)OOT style Octorok  (Read 3210 times)

0 Members and 1 Guest are viewing this topic.
(help)OOT style Octorok
« on: January 01, 2012, 11:46:35 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 448
So I've been working on an oot style octorok that appears out of the water when close enough and hides when too far away or too close, but have run into a snag....
Code: [Select]
//Create
//sets up current state
state = "hide"

//Step
//makes octorok appeaR or hide
if (distance_to_object(objLink)<48){
 state = "jump"}
 if (distance_to_object(objLink)>=48){
 state = "hide"}
 if (distance_to_object(objLink)<16){
 state = "hide"}

//sets up sprite based on octoroks current state
 switch state {
 case "hide": sprite_index=sprite13; break;
 case "jump": sprite_index=sprite12;image_speed=.5; break;
 case "idle": sprite_index=sproctorok;image_speed=.4; break;
 case "shoot":
 }
 
 //change state to idle after jumping up animation ends
 
 if (sprite_index=sprite12 and image_index=5){
  image_speed=0
 state="idle"
 }

Right now I have a problem changing from a jumping up animation to the idle state waiting to shoot. Any thoughts?
Logged

King Tetiro

Leader of Phoenix Heart
Re: (help)OOT style Octorok
« Reply #1 on: January 01, 2012, 11:50:17 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3549
I'll see what I can russle up tomorrow morning. Heading off to bed. What you basically want is a water version of what Deku Scrubs do?
Logged
  • Phoenix Heart
Re: (help)OOT style Octorok
« Reply #2 on: January 02, 2012, 12:06:54 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 448
Essentially, except the Octorok doesn't hide between shooting, it remains on top of the water vulnerable to projectile weapons.
Logged
Re: (help)OOT style Octorok
« Reply #3 on: January 02, 2012, 04:31:25 am »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Posts: 728
Not tested, but something that may help:

Code: [Select]
// Step Event

// If hiding and the target is within range, switch to jump state.
if (state == "hide" && distance_to_object(objLink) < 48)
{
    state = "jump";
    sprite_index = sprite12;
    image_speed = 0.5;
}

// If not already involved in an action state and target is out of bounds of set ranges, hide.
if (state != "jump" && state != "shoot" && (distance_to_object(objLink) >= 48 || distance_to_object(objLink) < 16))
{
    state = "hide";
    sprite_index = sprite13;
}

// Sets up sprite based on octoroks current state.
switch (state)
{
    case "jump":
        // If at the end of the jump animation, switch to idle state.
        if (image_index == 5)
            state = "idle";

        break;
     
    case "idle":
        sprite_index = sproctorok;
        image_speed = 0.4;
         
        // TODO: Condition for shoot state.
        break;

    case "shoot":
        // TODO: Condition back to idle state.
        break;
}
« Last Edit: January 02, 2012, 04:49:43 am by Xfixium »
Logged
  • Pyxosoft
Re: (help)OOT style Octorok
« Reply #4 on: January 05, 2012, 04:37:34 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 448
Thanks for the start X. One question though, I'm trying to go to a different state if you get to close called "dive". I set it up in the switch statement as
Code: [Select]
case "dive":
image_speed = .5
if (image_index == 5)
state = "hide";

break;
, it sets the correct sprite, but the animation just keeps repeating. Any idea what could be causing the problem?
Logged
Re: (help)OOT style Octorok
« Reply #5 on: January 05, 2012, 11:00:47 am »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
Did you set the image_speed to 0 when the animation was finished.


Edit: I made a quick state transition diagram I would use for the OOT octorock.
« Last Edit: January 05, 2012, 12:31:33 pm by Niek »
Logged
Re: (help)OOT style Octorok
« Reply #6 on: January 05, 2012, 01:48:49 pm »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Posts: 728
Thanks for the start X. One question though, I'm trying to go to a different state if you get to close called "dive". I set it up in the switch statement as
Code: [Select]
case "dive":
image_speed = .5
if (image_index == 5)
state = "hide";

break;
, it sets the correct sprite, but the animation just keeps repeating. Any idea what could be causing the problem?

Does the animation have 6 frames (sub-images)? Also, it's good practice to use something like floor(image_index) == 5 for future reference as the image_index can be fractional.

Nice diagram btw Niek.
Logged
  • Pyxosoft
Re: (help)OOT style Octorok
« Reply #7 on: January 06, 2012, 03:37:46 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 448
Yes, the animation has 6 frames(same animation as jumping up), and it doesn't like it when I set the animation speed to 0, the animation stops at the last frame but doesn't change the objects state. And yeah Niek, that was my plan for the transitions, except adding a rest period if you get to close and make it disappear, so that way it won't pop right back up if you move back within range.
Logged
Re: (help)OOT style Octorok
« Reply #8 on: January 06, 2012, 04:39:35 pm »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Posts: 728
You'll probably have to post the whole code.
Logged
  • Pyxosoft
Re: (help)OOT style Octorok
« Reply #9 on: January 07, 2012, 09:50:23 am »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
Okay I took a closer look at your code. I noticed that you want to use states in your implementation. But you are doing something critically wrong. First you change the state but you do not change the attributes to state valid values. Now the "state" attribute is just that. Another attribute in a list of attributes to check. Read this to learn how to implement states in GML: http://zfgc.com/forum/index.php?topic=38782.0  Xfixium's code is a lot better but not completely correct either.

I'll try based on the code you have provided to offer you a solution, but it isn't tested and like Xfixium says it is best to see the whole code you have now.
Code: Text
  1. state = "hide";
  2. sprite_index = sprite13;
  3. image_speed = 0;         // I assume that there is no animation during hiding.
  4. image_index = 0;
  5.  

Code: Text
  1. if( state == "hide")
  2. {
  3.     if(distance_to_object(objLink) < 48 && distance_to_object(objLink) >= 16)
  4.     {
  5.          state = "jump";
  6.          sprite_index = sprite12;
  7.          image_speed = 0.5;
  8.          image_index = 0;
  9.     }
  10. }
  11. else if( state == "jump")
  12. {
  13.       if (image_index == 5)
  14.       {
  15.            state = "idle";
  16.            sprite_index = sproctorok;
  17.            image_speed = 0.4;
  18.            image_index = 0;
  19.       }
  20. }
  21. else if( state == "idle")
  22. {
  23.       //condition to go back to hiding following dive
  24.       if(distance_to_object(objLink) >= 48 && distance_to_object(objLink) < 16)
  25.       {
  26.             state = "dive";
  27.             sprite_index = sprOctDive;  // or whatever sprite you use for diving
  28.             image_speed = 0.5;
  29.             image_index = 0;
  30.       }
  31.       //condition to go to shooting
  32.       else if( shootTimer > shootLimit ) // This you have to change to whatever you use
  33.       {
  34.             state = "shoot";
  35.             sprite_index = sprOctShoot;  //or whatever sprite you use.
  36.             image_speed = 0.5;
  37.             image_index = 0;
  38.       }
  39. }
  40. else if( state == "shoot")
  41. {
  42.       //condition for going back to idle
  43.       if( image_index == ?? )
  44.       {
  45.            state = "idle";
  46.            sprite_index = sproctorok;
  47.            image_speed = 0.4;
  48.            image_index = 0;
  49.       }
  50. }
  51. else if( state == "dive")
  52. {
  53.       //condition for going to hide
  54.       if(image_index == 5)
  55.       {
  56.            state = "hide";
  57.            sprite_index = sprite13;
  58.            image_speed = 0;
  59.            image_index = 0;
  60.       }
  61. }
  62. else
  63. {
  64.       //you are in an error state best to resolve this
  65.       ... throw message
  66.  
  67.       //OR
  68.       ... set to hide state
  69.        state = "hide";
  70.        sprite_index = sprite13;
  71.        image_speed = 0;
  72.        image_index = 0;
  73. }
  74.  

This does not work as it misses a lot of implementation that you hadn't provided yet. Bor doe it have the states 'rest', 'hurt' and 'die' in it. But I hope it helps you forward.

PS: when changing the sprite during a state transition it is best to set the "image_index" to 0 again, or your animation starts where the previous use of that sprite left off.
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.044 seconds with 55 queries.