Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1066947 Posts in 43553 Topics- by 35598 Members - Latest Member: Ikkks

November 26, 2014, 09:24:41 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Weird animation bug?
Pages: [1]
Print
Author Topic: Weird animation bug?  (Read 534 times)
Rabbit
Level 10
*****


i can do what i want

TheRabbitInferno
View Profile WWW Email
« on: April 06, 2013, 09:25:43 AM »

So here is my situation.

When you are aiming (holding the gun up and looking down the sight) the movement animation changes and movement slows down. The problem I currently have is that when aiming and moving to the right, the animation won't play. It just gets stuck on the first frame.

However, if you move to the left the animation will play in reverse as it should. After moving left, and then moving right again, the animation WILL PLAY but only as many cycles as it had previously played in reverse. Here is an example followed by the code I have in place.


(yeah when facing left the animations don't play correctly but I know how to fix it)

Code:
if (aim && onGround && !crouch){
    sprite_index = sRedAim;
    image_speed = 0;
    xSpeed = 0;
         if (left){
            sprite_index = sRedAimMove;
            image_speed  = -0.2;
            xSpeed       = -1;
        }else if (right){
            sprite_index = sRedAimMove;
            image_speed  = 0.2;
            xSpeed       = 1;
        }

I actually need a bit more help in terms of animation for this project and I am willing to pay for a tutor essentially. But yeah. All help is greatly appreciated!
Logged

soryy708
Level 3
***


Where is my tea?


View Profile Email
« Reply #1 on: April 06, 2013, 10:23:59 AM »

Alittle bit more code could be useful.

Please note that a bug that seems to come from one system actually originates in another  Gentleman

To begin with, your currently posted code looks okay (at first glance atleast). The problem's likely somewhere else.
Logged

Portfolio:
  • Cacto Loco! - 'Additional Tunes' (Composer)
  • To be continued...
Rabbit
Level 10
*****


i can do what i want

TheRabbitInferno
View Profile WWW Email
« Reply #2 on: April 06, 2013, 10:55:06 AM »

Its actually the only code that is in use, as I've commented out the rest for testing. However here is his entire movement/animation code.

Code:
//movement//
if (aim && onGround && !crouch){
    sprite_index = sRedAim;
    image_speed = 0;
    xSpeed = 0;
         if (left){
            sprite_index = sRedAimMove;
            image_speed  = -0.2;
            xSpeed       = -1;
        }else if (right){
            sprite_index = sRedAimMove;
            image_speed  = 0.2;
            xSpeed       = 1;
        }
}else if (left){
    image_xscale = -1;
    sprite_index = sRedRun;
    image_speed = 0.5;
    xSpeed = -6;
}else if (right){
    image_xscale = 1;
    sprite_index = sRedRun;
    image_speed = 0.5;
    xSpeed = 6;
}else if (crouch && onGround && !aim){
    sprite_index = sRedCrouch;
    xSpeed = 0;
}else{
    sprite_index = sRedStand;
    xSpeed = 0;
}
Logged

ஒழுக்கின்மை
Level 10
*****


Also known as रिंकू.

RinkuHero
View Profile WWW Email
« Reply #3 on: April 06, 2013, 11:11:14 AM »

that still isn't all the code. you aren't explaining how left and right and aim and onground and crouch are set, for example. you aren't showing the code for setting and unsetting those variables
Logged

Rabbit
Level 10
*****


i can do what i want

TheRabbitInferno
View Profile WWW Email
« Reply #4 on: April 06, 2013, 11:12:16 AM »

Okay. Here is this.

Code:
left    = (keyboard_check(ord("A")));
right   = (keyboard_check(ord("D")));
aim     = (keyboard_check(ord("W")));
crouch  = (keyboard_check(ord("S")));

This simply sets left/right/aim to true or false. All input works this way.

In another script that gets called in Create, along with all of the player variables, these are all set to "false" by default.

And here is how onGround is defined, along with some other things.

Code:
//vertical collision//
if (place_meeting(x,y+ySpeed,oBlocker)){
    while (!place_meeting(x,y+sign(ySpeed),oBlocker)) y += sign(ySpeed);
    ySpeed = 0;
    onGround = true;
}else if (place_meeting(x,y+ySpeed,oBlock)){
    while (!place_meeting(x,y+sign(ySpeed),oBlock)) y += sign(ySpeed);
    ySpeed = 0;
    onGround = true;
}else{
    sprite_index = sRedJump;
    onGround = false;
}
« Last Edit: April 06, 2013, 11:25:04 AM by Rabbit » Logged

ஒழுக்கின்மை
Level 10
*****


Also known as रिंकू.

RinkuHero
View Profile WWW Email
« Reply #5 on: April 06, 2013, 01:20:55 PM »

have you used debug mode yet, with all of those variables listed, to see if there's any difference between the two situations you mention (aiming + moving left vs aiming + moving right)? make sure sprite_index and image_speed are included in that debug variable list
Logged

Rabbit
Level 10
*****


i can do what i want

TheRabbitInferno
View Profile WWW Email
« Reply #6 on: April 06, 2013, 02:07:07 PM »

have you used debug mode yet, with all of those variables listed, to see if there's any difference between the two situations you mention (aiming + moving left vs aiming + moving right)? make sure sprite_index and image_speed are included in that debug variable list

I have not. I dunno how debug mode works in Studio. I know nothing. I am a baby.
Logged

ஒழுக்கின்மை
Level 10
*****


Also known as रिंकू.

RinkuHero
View Profile WWW Email
« Reply #7 on: April 06, 2013, 02:08:41 PM »

i think it works the same way it does in gm7 last i checked -- you just run in debug mode (the red arrow) and type in the variables you want to track
Logged

Rabbit
Level 10
*****


i can do what i want

TheRabbitInferno
View Profile WWW Email
« Reply #8 on: April 06, 2013, 02:25:32 PM »

I will try that. I've never used it in any version of GM honestly. Everything I've worked on has been simple enough to just know what is happening haha.

Aha! So here is what is happening, though I don't know why.

Left, right, aim, etc are all firing as they should. Changing from 1 to 0 and 0 to 1 when appropriate. What I have found is that when aiming, and moving right, the image index does not increase which is effectively keeping the sprite from animating.

When aiming and moving left however, the sprite index starts decreasing infinitely until you push aim and right. At which point it starts increasing until it hits 0, and stops.

It is not simply cycling the number of frames in the animation like it should be. For example when running, the index climbs from 0 to 15 and then resets back to 0 to loop the animation. This is not happening.
« Last Edit: April 06, 2013, 02:35:19 PM by Rabbit » Logged

ஒழுக்கின்மை
Level 10
*****


Also known as रिंकू.

RinkuHero
View Profile WWW Email
« Reply #9 on: April 06, 2013, 04:10:08 PM »

going infinitely negative isn't a problem because GM uses "mod" to determine which to use. in other words, if a sprite has 15 frames, numbered 0 to 14, it does "image_index mod 15" which always keeps it in the range between 0 and 14

not increasing when it should is probably the problem. when it doesn't increase, and it should increase, is image_speed 0, or 0.2? according to your code, when you want image_index to increase, image speed should be 0.2. when the animation doesn't increase when you want it to increase, what is image_speed's value?
Logged

Rabbit
Level 10
*****


i can do what i want

TheRabbitInferno
View Profile WWW Email
« Reply #10 on: April 06, 2013, 04:49:52 PM »

image_speed is acting as it should. its set on 0.2 and when moving left its -0.2.

I took a cap of the stats in motion. I dont know if I may be missing something.

Logged

ஒழுக்கின்மை
Level 10
*****


Also known as रिंकू.

RinkuHero
View Profile WWW Email
« Reply #11 on: April 06, 2013, 04:55:45 PM »

you said above that the image_index doesn't increase; but it is increasing in that gif (it's going from a higher negative number to a lower negative number, which is an increase)
Logged

Rabbit
Level 10
*****


i can do what i want

TheRabbitInferno
View Profile WWW Email
« Reply #12 on: April 06, 2013, 04:59:26 PM »

you said above that the image_index doesn't increase; but it is increasing in that gif (it's going from a higher negative number to a lower negative number, which is an increase)

Well right but it will not increase beyond 0.2~8 or whatever it is. So its not animating when moving forward.

Compare this to the basic running sprite. It increases from 0 to 15, then resets back to 0 to repeat as long as necessary.
Logged

ஒழுக்கின்மை
Level 10
*****


Also known as रिंकू.

RinkuHero
View Profile WWW Email
« Reply #13 on: April 06, 2013, 05:49:18 PM »

do you mean that image_speed reverts to -0.2 from 0.2 when image_index reaches around 0, or what?
Logged

Rabbit
Level 10
*****


i can do what i want

TheRabbitInferno
View Profile WWW Email
« Reply #14 on: April 06, 2013, 05:58:33 PM »

I can pack this into a zip and let you check it out if you'd like.
Logged

BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #15 on: April 07, 2013, 03:44:03 AM »

Is it because you are setting the sprite_index to sRedAim every frame before changing it to sRedAimMove. I know little about GM, so as a hypothesis I would guess that sRedAim has only one frame of animation, so it is wrapping image_index to be less than 1 every time you set the sprite_index like so.

Checking a gifexplode, there are some frames where image_speed is consistenly 0.2, but image_index randomly hops around the 0-1 range. Strange. You should check other areas you set image_index.
Logged
Rabbit
Level 10
*****


i can do what i want

TheRabbitInferno
View Profile WWW Email
« Reply #16 on: April 07, 2013, 05:56:49 AM »

Guh. I feel like an idiot. I restructured the code to have the aim movement at the top, and aim idle at the bottom and its fixed!

Thanks Boris.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic