Ducking with animation frames only (platformer)

User avatar
Mugi
Posts: 508
Joined: Thu Dec 27, 2018 8:30 pm

Ducking with animation frames only (platformer)

Post by Mugi » Tue Jan 08, 2019 12:33 pm

I'm not sure how useful this is to other people, but in my game, im REALLY needing the action states for other things, and
ducking i wanted to have, but ducking is more or less just a visual and doesnt really serve any purpose that would warrant it to get an action state of it's own.
(in my game, a down press of dpad is just hardcoded to do things.)

so i put together a set of inputs that make the player enter a ducking animation derived from idle state, instead of going into ducking action state.

here's how it's done;

1) make sprite for "ducking left" and "ducking right"
2) assign the sprites in your idle state (action state 00) in positions "down right" and "down left"

Image

3) make 2 new Input script, duck.asm and releaseDuck.asm

here's the code:

duck.asm

Code: Select all

    ;FACE_DOWN_RIGHT    = #%00000001    ; we use this to crouch, facing right.
    ;FACE_RIGH          = #%00000010
    
    ;FACE_LEFT          = #%00000110
    ;FACE_DOWN_LEFT     = #%00000111    ; we use this to crouch, facing left.
    LDX player1_object
    
    LDA gamepad
    AND #%11010000
    BNE skipCrouch

    LDA Object_movement,x
    CMP #%00000110
    BEQ faceLeft
    StopMoving player1_object, STOP_RIGHT
    StopMoving player1_object, STOP_LEFT
    FaceDirection player1_object, FACE_DOWN_RIGHT
    RTS
    
faceLeft:
    StopMoving player1_object, STOP_RIGHT
    StopMoving player1_object, STOP_LEFT
    FaceDirection player1_object, FACE_DOWN_LEFT
skipCrouch:
    RTS
releaseDuck.asm:

Code: Select all

    LDX player1_object
    LDA Object_movement,x
    CMP #%00000111
    BEQ faceLeft_noCrouch
    ChangeObjectState #$00, #$03
    FaceDirection player1_object, FACE_RIGHT
    RTS
faceLeft_noCrouch:
    ChangeObjectState #$00, #$03
    FaceDirection player1_object, FACE_LEFT
    RTS
assign duck.asm in input editor to "Press Down" and releaseDuck.asm to "Release Down"
enjoy ducking without wasting an action state :)



feel free to improve the code, im not the best of assembly programmers :P
User avatar
dale_coop
Posts: 3487
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: Ducking with animation frames only (platformer)

Post by dale_coop » Tue Jan 08, 2019 12:35 pm

Smart! Love it. Thanks Mugi, for sharing that <3
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
GX79
Posts: 4
Joined: Wed Feb 20, 2019 12:19 pm

Re: Ducking with animation frames only (platformer)

Post by GX79 » Fri Mar 15, 2019 5:01 pm

Is it possible to temporarily ignore the top collision points so you can avoid enemies when ducking?
User avatar
Mugi
Posts: 508
Joined: Thu Dec 27, 2018 8:30 pm

Re: Ducking with animation frames only (platformer)

Post by Mugi » Fri Mar 15, 2019 5:07 pm

yes, it's a flag of object_vulnerability (i dont remember which one)
all you have to do is make your input script to write that flag as 1 when you're ducking and remove it when you're not.
digit2600
Posts: 173
Joined: Mon Apr 16, 2018 9:50 pm

Re: Ducking with animation frames only (platformer)

Post by digit2600 » Sat Mar 16, 2019 4:40 am

In object actions theres an ignore top collision flag. I only just discovered it last week lol... meanwhile I was trying to do it in code and having no luck
User avatar
Mugi
Posts: 508
Joined: Thu Dec 27, 2018 8:30 pm

Re: Ducking with animation frames only (platformer)

Post by Mugi » Sat Mar 16, 2019 4:53 am

the thing is that if you do your ducking like this (using a face direction of idle state) you cant set the object flag to the idle state as it would cut the hitbox during idle.
that flag can be set in code though, which is nice because this method spares you from using an action state for your ducking.
User avatar
Lother
Posts: 107
Joined: Tue Mar 06, 2018 5:30 pm
Location: France

Re: Ducking with animation frames only (platformer)

Post by Lother » Wed Mar 20, 2019 11:27 pm

I tried to use your code for Crouching in my game, but I crouch a second time I get that strange glitch shown in the video below.



I also want to duplicate and use that code but for my character looking up while pressing UP. What are the few modification I have to do for this to work ?

(Oh, and you can also see a new boss enemy I'm working on too.)
_____
The game I'm currently working on : FIGHT OF THE PHOENIX

One of the 2D graphical artist who worked on MonsterBoy and the Cursed Kingdom.
User avatar
dale_coop
Posts: 3487
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: Ducking with animation frames only (platformer)

Post by dale_coop » Thu Mar 21, 2019 12:29 am

You might have this kind of glitch when you don't have the same frame count for your animations (check that all the animations assigned to a animation type have the same frame count).
Or it might happen because your animations are using too much memory (size or your player too big or too much frames)... Make a backup of your project (or your objects) and try redoing the animation frames.
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
User avatar
Lother
Posts: 107
Joined: Tue Mar 06, 2018 5:30 pm
Location: France

Re: Ducking with animation frames only (platformer)

Post by Lother » Thu Mar 21, 2019 2:01 am

dale_coop wrote:
Thu Mar 21, 2019 12:29 am
You might have this kind of glitch when you don't have the same frame count for your animations (check that all the animations assigned to a animation type have the same frame count).
Or it might happen because your animations are using too much memory (size or your player too big or too much frames)... Make a backup of your project (or your objects) and try redoing the animation frames.
That was indeed the count of frames that was different between the Ducking animation and the Idle one.
_____
The game I'm currently working on : FIGHT OF THE PHOENIX

One of the 2D graphical artist who worked on MonsterBoy and the Cursed Kingdom.
User avatar
Lother
Posts: 107
Joined: Tue Mar 06, 2018 5:30 pm
Location: France

Re: Ducking with animation frames only (platformer)

Post by Lother » Thu Mar 21, 2019 3:31 am

Ok, so I've been trying to fiddle the scripts around in order for my character to play a special animation whenpressing Up with these codes:

lookup.asm

Code: Select all

    ;FACE_UP_RIGHT    = #%00000011    ; we use this to crouch, facing right.
    ;FACE_RIGH          = #%00000010
    
    ;FACE_LEFT          = #%00000110
    ;FACE_UP_LEFT     = #%00000101    ; we use this to crouch, facing left.
    LDX player1_object
    
    LDA gamepad
    AND #%11010000
    BNE skipCrouchToo

    LDA Object_movement,x
    CMP #%00000110
    BEQ faceLeftToo
    StopMoving player1_object, STOP_RIGHT
    StopMoving player1_object, STOP_LEFT
    FaceDirection player1_object, FACE_UP_RIGHT
    RTS
    
faceLeftToo:
    StopMoving player1_object, STOP_RIGHT
    StopMoving player1_object, STOP_LEFT
    FaceDirection player1_object, FACE_UP_LEFT
skipCrouchToo:
    RTS
And releaseLookup.asm:

Code: Select all

    LDX player1_object
    LDA Object_movement,x
    CMP #%00000101
    BEQ faceLeft_noUp
    ChangeObjectState #$00, #$03
    FaceDirection player1_object, FACE_RIGHT
    RTS
faceLeft_noUp:
    ChangeObjectState #$00, #$03
    FaceDirection player1_object, FACE_LEFT
    RTS
But the animation doesn't play when pressing Up. Any idea how to make that work? (The animations are set up to "Up Right" and "Up Left" in the idle animation type.)
_____
The game I'm currently working on : FIGHT OF THE PHOENIX

One of the 2D graphical artist who worked on MonsterBoy and the Cursed Kingdom.
Post Reply