Smooth Grid Movement with complete Animation

jsorr2jsorr2 Member Posts: 279
edited November 2014 in Working with GS (PC)

Hey!

I'm wondering how to animate an actor after a key is un-pressed but the actor is still moving.

For example:
when key UP is pressed

move x = 0, y = 32.
Animate.

*User lets go of key when Y = 16.
*Animation stops.
*Actor moves forward remaining 16 to make Y=32.

How to make the actor animate for remaining 16 so it doesnt just slide if there is no input from the user?

Answers

  • Simple AppsSimple Apps Member Posts: 158
    edited November 2014

    When key is down ( Change attribute motion linear velocity y to 32)
    otherwise
    velocity y to zero

    Good Luck

  • jsorr2jsorr2 Member Posts: 279
    edited November 2014

    @Simple Apps
    I tried that out, it moves smoothly, but it doesn't move y position 32 forward, it moves at the speed of 32 along the y position.

  • SocksSocks London, UK.Member Posts: 12,822
    edited November 2014

    @jsorr2 said:
    @Simple Apps
    I tried that out, it moves smoothly, but it doesn't move y position 32 forward, it moves at the speed of 32 along the y position.

    When the key is pressed - Move to:

    X = 0

    Y = 32

    Relative to actor.

    I know you are on a PC, but here is what it should look like on a Mac . .

  • SocksSocks London, UK.Member Posts: 12,822
    edited November 2014

    . . . or if you want to be able to hold down the key and have the movement repeat . . .

  • jsorr2jsorr2 Member Posts: 279

    @Socks‌ I had something similar to this with interpolate, but i cant figure out how to continue the animation till the actor stops moving (veloctiy doesnt work) because when you let go of the UP key, the animation stops but the actor still moves till it reaches Y=32. It just looks like the actor is sliding till it reaches y 32

  • SocksSocks London, UK.Member Posts: 12,822
    edited November 2014

    @jsorr2 said:
    . . . i cant figure out how to continue the animation till the actor stops moving (veloctiy doesnt work) . . .

    I don't understand any of that, I don't understand the relationship between the animation behaviour and velocity, the two are not connected in any way (at least not by default).

    @jsorr2 said:
    because when you let go of the UP key, the animation stops but the actor still moves till it reaches Y=32. It just looks like the actor is sliding till it reaches y 32

    There is no built-in reason that an animation should stop when you let go of a key - unless you have set your code up to specifically make that happen.

  • jsorr2jsorr2 Member Posts: 279
    edited November 2014

    @Socks‌ as an example: i press up key, actor moves forward y=32 and animation plays until i let go of the Up key. I let go of the up key when Y = 16, the animation stops, the movement doesnt stop because the actor MUST be at y=32.

    Tldr; animation is set to play when key is down, not when actor is moving. So if actor moves and key isnt down, animation doest play

    edit: sorry for being vague. I guess i assumed the only way to animate was when a key was pressed. Is there another way to animate my actor while its moving instead of when a key is pressed?
    If thats too vague as well I'll upload a video and my code tomorrow

  • SocksSocks London, UK.Member Posts: 12,822

    @jsorr2 said:
    Socks‌ as an example: i press up key, actor moves forward y=32 and animation plays until i let go of the Up key. [if] I let go of the up key when Y = 16, the animation stops, the movement doesnt stop because the actor MUST be at y=32.

    Wrap your animation in a rule that says:

    When linear velocity Y > than 0.

  • Simple AppsSimple Apps Member Posts: 158

    You should keep in loop in the animate behaviour of your animation

  • SocksSocks London, UK.Member Posts: 12,822
    edited November 2014

    @Simple Apps said:
    You should keep in loop in the animate behaviour of your animation

    He might not want his animation to loop ?

  • jsorr2jsorr2 Member Posts: 279
    edited November 2014

    @socks That solved my problem of animating while moving, however, the animation doesnt play properly. it seems to only play the first 2 out of 4 images and it plays them rapidly, even if the fps is 1.
    I entered the exact code you suggested.

    here is a download of my project, would be awesome if you could quickly check it out.
    https://www.mediafire.com/?0ha3k0om77b8h9f
    All i want is my character to walk down and play the 4 picture animation while it moves.

  • SocksSocks London, UK.Member Posts: 12,822
    edited November 2014

    @jsorr2 said:
    I entered the exact code you suggested.

    Exactly ? Or just kinda' similar ? ;)

    Is the actor moving down ?

  • Simple AppsSimple Apps Member Posts: 158
    edited November 2014
  • jsorr2jsorr2 Member Posts: 279
    edited November 2014

    @Socks‌
    If i did Y > than 0 while going down it didnt animate.
    If i did Y < than 0 it did animate but the animation was terrible.
    @‌ simpleapps
    Changing frame rate does nothing, aye.

    Take a gander at my project if you have some time :)

  • SocksSocks London, UK.Member Posts: 12,822

    @jsorr2 said:
    . . . If i did Y < than 0 it did animate but the animation was terrible.

    Seems to work fine for me.

    Also you might be better off using tiling or even replicate to reproduce all those tree actors, it will be much easier to do and put a lot less strain on the game.

  • jsorr2jsorr2 Member Posts: 279

    @Socks‌ Thanks for showing me how to tile!
    I'm slowly understanding how animation works. In the video you changed your movement to 100 forward, instead of 32. If it's 32 forward the animation doesnt play through the 4 images because there isn't enough time.

    Is there anyway i can move forward, play animation 1(left foot forward), then when i move forward again, play animation 2(right foot forward)?

  • SocksSocks London, UK.Member Posts: 12,822

    @jsorr2 said:
    In the video you changed your movement to 100 forward, instead of 32.

    Yes, just so we had some clear movement to look at.

    @jsorr2 said:
    If it's 32 forward the animation doesnt play through the 4 images because there isn't enough time.

    The apply some simple maths - how far is it moving / at what speed (measured in pixels per second) / then calculate what frame rate you need to animation to be to play the number of frames you need to play.

    @jsorr2 said:
    Is there anyway i can move forward, play animation 1(left foot forward), then when i move forward again, play animation 2(right foot forward)?

    Sure, I think beyond things outside the feature set of GS you can do pretty much anything, if you want the colour of an actor to control the volume of a sound playing on another actor or the speed of rotation to define the width of an actor then all that stuff is very straightforward . . . so basically yes.

    The frames in an animation actually change the actor's image . . . so while the animation is running, the actors images is called attack01, then attack02, then attack03, then attack04 and so on . . . so you can use this information for very fine control over your animations.

    For example you could have a move that stops when self.image is attack03, or have an actor that destroys itself when self.image contains "04" . . . . and so on, hope that makes sense.

  • jsorr2jsorr2 Member Posts: 279

    @Socks said:
    The apply some simple maths - how far is it moving / at what speed (measured in pixels per second) / then calculate what frame rate you need to animation to be to play the number of frames you need to play.

    Wow! it makes sense now. If I have 64 speed and move 32 pixels, it will move 32 pixels in 0.5 seconds. therefore if i had 4 images, I would need 8 fps animation to play all 4 in 0.5 seconds. That took ages to figure out

    @Socks said:
    For example you could have a move that stops when self.image is attack03, or have an actor that destroys itself when self.image contains "04" . . . . and so on, hope that makes sense.

    I made it so if self.image contained Walk3 (which is what i named my animation picture) it would be destroyed, and it worked! You're a wealth of information Socks, thank you.

    How could i make the program remember what animation in a sequence it was up to, and play the next animation once a key was pushed? (i.e. actor used left foot animation before, next animation should be right foot if key is pressed)

  • SocksSocks London, UK.Member Posts: 12,822

    @jsorr2 said:
    Wow! it makes sense now. If I have 64 speed and move 32 pixels, it will move 32 pixels in 0.5 seconds. therefore if i had 4 images, I would need 8 fps animation to play all 4 in 0.5 seconds. That took ages to figure out

    By Jove, I think he's got it !

    :wink:

    Duration is duration in seconds, game.time is in seconds, speed is pixels per second, rotation speed is degrees per second, frames per second is - obviously - how many frames every second . . . and so on, just chop it all up and stick it in the maths mincer.

    @jsorr2 said:
    I made it so if self.image contained Walk3 (which is what i named my animation picture) it would be destroyed, and it worked! You're a wealth of information Socks, thank you.

    Cool ! It works ! :smile:

    @jsorr2 said:
    How could i make the program remember what animation in a sequence it was up to

    You need to define 'was up to', presumably something happens so that the animation will not just continue, whatever that thing is that you call 'was up to' can be used to copy the current frame into an attribute or a table or that sort of thing . . .

    When actor does X or when key is released or pressed or whatever or when frame = XX or when timer > 0.24 seconds . . . (or whatever) change game.ThisWasTheLastFrameUsed to self.image . . . this stores the current frame in game.ThisWasTheLastFrameUsed.

    @jsorr2 said:
    and play the next animation once a key was pushed?

    I don't know, not at my computer right now, but something like change image to game.ThisWasTheLastFrameUsed + 1 should work, not that exactly, but that sort of thing.

  • jsorr2jsorr2 Member Posts: 279
    edited November 2014

    @Socks‌ thanks for your help socks :)

Sign In or Register to comment.