Topic: set_player_position issue

can anyone tel me what I doing wrong?

I'm working on a tree, if the player touches the top of the tree it goes down (state "movingdown").
Then he go back up again (state "moveup").
the player is hanging on the branches, The player must move along.
The player goes down in state "movingdown" but in state "moveup" he goes also down!
How can I fix this?

Thanks smile

Code

    //moving down
    state "movingdown"
    {
        //animation
        set_animation SS_boom 1

        //beweeg -50 -50
        let "$y = $y + 2"
        let "$x = $x + 2"
        set_player_position "60-$x" "-200+$y"

        //verder
        on_animation_finished "moveup"

    }
    //move up
    state "moveup"
    {
        //animation
        set_animation SS_boom 2

        //beweeg -50 -50
        let "$y = $y - 2"
        let "$x = $x - 2"
        set_player_position "60-$x" "-200+$y"
    }
http://ssdw.nl/forum/getforumpic.php

Re: set_player_position issue

First of all, since the fps rate is not constant on all computers, you must not move the player with set_player_position - unless you multiply the speed (+2 or -2 in your case), by dt(). Use move instead - it already does the hard work for you (and then you do set_player_position 0 0).

Other than that, I don't see any errors. Maybe there's a logic error somewhere else. Maybe it isn't going to the moveup state at all. We'd need to take a look at the whole object.

Re: set_player_position issue

here the full code. I see now problem.

object "tree_catapult"
{
    state "main"
    {
        //create object
        create_child ".tree_catapults" 60 -200

        //change state
        change_state "notmoving"
    }

    //not moving
    state "notmoving"
    {
        //animation
        set_animation SS_boom 0
    }

    //moving down
    state "movingdown"
    {
        //animation
        set_animation SS_boom 1

        //beweeg -50 -50
        let "$y = $y + 2"
        let "$x = $x + 2"
        set_player_position "60-$x" "-200+$y"

        //verder
        on_animation_finished "moveup"

    }
    //move up
    state "moveup"
    {
        //animation
        set_animation SS_boom 2

        //beweeg -50 -50
        let "$y = $y - 2"
        let "$x = $x - 2"
        set_player_position "60-$x" "-200+$y"
    }
}


//-------------Players------------------------------------------------------------------------------------------------------------
//surge
object ".tree_catapults"
{


    state "main"
    {
        // only for surge
        observe_player "surge" 

        //toch
        on_player_rect_collision -25 -25 25 25 "move"
    }
    state "move"
    {
        change_closest_object_state "tree_catapult" "movingdown"
        set_player_animation "SD_SONIC" 25
    }

}
http://ssdw.nl/forum/getforumpic.php

Re: set_player_position issue

We can't test it without the animations.

ssdw wrote:

I see now problem

what?

Re: set_player_position issue

Alexandre wrote:

We can't test it without the animations.

sorry! here

sprite:

// DNA Door
sprite SS_boom
{
    source_file     images/boom.png
    source_rect     0 0 1000 500
    frame_size      250 250
    hot_spot        125 250

    // not moving
    animation 0
    {
        repeat      TRUE
        fps         16
        data        6
    }

    // moving down
    animation 1
    {
        repeat      TRUE
        fps         16
        data        6 5 4 3 2 1 0
    }

    // moving up
    animation 1
    {
        repeat      FALSE
        fps         16
        data        0 1 2 3 4 5 6
    }
}

image:
http://upload.surgeswarehouse.com/upload/boom.PNG


Alexandre wrote:

What?

i mean I see no problem in the code.

http://ssdw.nl/forum/getforumpic.php

Re: set_player_position issue

In cases like this you can use textout to see what's going on. What I saw is that both states do what they should, but the object spends much more time in movingdown than in movingup. It keeps alternating between states.

 19     //moving down
 20     state "movingdown"
 21     {
 22         //animation
 23         set_animation SS_boom 1
 24 
 25         //beweeg -50 -50
 26         let "$y = $y + 2*dt()"
 27         let "$x = $x + 2*dt()"
 28         set_player_position "60-$x" "-200+$y"
 29 textout default 0 -100 "y: $y"
 30 
 31         //verder
 32         on_animation_finished "moveup"
 33 
 34     }
 35     //move up
 36     state "moveup"
 37     {
 38         //animation
 39         set_animation SS_boom 2
 40 
 41         //beweeg -50 -50
 42         let "$y = $y - 2*dt()"
 43         let "$x = $x - 2*dt()"
 44         set_player_position "60-$x" "-200+$y"
 45 textout default 0 -100 "<color=ffff00>y: $y</color>"                                                                                            
 46     }

Re: set_player_position issue

Alexandre wrote:

In cases like this you can use textout to see what's going on. What I saw is that both states do what they should, but the object spends much more time in movingdown than in movingup. It keeps alternating between states.

 19     //moving down
 20     state "movingdown"
 21     {
 22         //animation
 23         set_animation SS_boom 1
 24 
 25         //beweeg -50 -50
 26         let "$y = $y + 2*dt()"
 27         let "$x = $x + 2*dt()"
 28         set_player_position "60-$x" "-200+$y"
 29 textout default 0 -100 "y: $y"
 30 
 31         //verder
 32         on_animation_finished "moveup"
 33 
 34     }
 35     //move up
 36     state "moveup"
 37     {
 38         //animation
 39         set_animation SS_boom 2
 40 
 41         //beweeg -50 -50
 42         let "$y = $y - 2*dt()"
 43         let "$x = $x - 2*dt()"
 44         set_player_position "60-$x" "-200+$y"
 45 textout default 0 -100 "<color=ffff00>y: $y</color>"                                                                                            
 46     }

problem is solved!
object ".tree_catapults" changed the state repeatedly in "movingdown".
this is now fixed!

Thank you smile

http://ssdw.nl/forum/getforumpic.php