Continue walking or Idle animation, after jumping....


👉Blast3D is now FREE👈

Support Future Updates by Becoming a Blitz Backer on Patreon.

 

Tweet
WazMeister

Hello all,

I've read posts, sample codes etc but am really struggling to have my animation continue with walking or idle after doing a jump (gravity + animation). Playing for hours and changing things either breaks the animation for jump or all animations.......
I managed to get Idle and walking animations working with the jump animation, albeit after jumping the walk and idle animations would not then work..
After messing around i'm at the point of walk and idle working again, but jump animation wont play at all.

Could someone find the time to review my code and perhaps see where I've gone wrong? Please consider I'm new and learning all this as I make so basic details are most welcome!

Showing both functions that control movement and animations:

Thanks in advanced.

Function object_key_control(obj)

; Player Movement
If KeyDown(w_key) = True Then MoveEntity obj, 0, 0, 0.7
If KeyDown(s_key) = True Then MoveEntity obj, 0, 0, -0.4
If KeyDown(d_key) = True Then TurnEntity obj, 0, -2, 0
If KeyDown(a_key) = True Then TurnEntity obj, 0, 2, 0

obj_x# = EntityX(obj):obj_z# = EntityZ(obj):obj_y# = EntityY(obj)

PlayerYVel# = PlayerYVel# - Gravity#

If onground = True And KeyHit(57) Then
    PlayerYVel# = .85
    onground = False
    jumping = True
EndIf

; If player is on the ground (i.e collided with the on the Plane Entity)
If EntityCollided(obj, 2) Then
    onground = True
    jumping = False
    ;PlayerYVel# = 0.0
EndIf

TranslateEntity player, 0, playerYVel#, 0

; Object hug the terrain (follow its heights) so dont run through it
If obj_y < TerrainY(land, obj_x, 0, obj_Z) Then
    PositionEntity obj, obj_x, TerrainY(land, obj_x, 0, obj_Z)+ 5, obj_z
EndIf

End Function

Function AnimatePlayer()

;Trigger Global variables to trigger flag walk (if moving or not)
walk = 0
If KeyDown(w_key) Or KeyDown(s_key) Then
    walk = 1
    If KeyDown(w_key) Or KeyDown(s_key) Then
        start_idle = 1
    Else
        walk = 0
    EndIf
Else
    walk = 0
EndIf

;Trigger Global variables to trigger animation.
If KeyDown(w_key) Then
    move_forward = move_forward + 1
Else
    move_forward = 0
EndIf

If KeyDown(s_key) Then
    move_backward = move_backward + 1
Else
    move_backward = 0
EndIf

; Animate The player walking forward or backward
If move_forward = 1 Then
    Animate player, 1, 0.7, player_walk, 10.0
EndIf

If move_backward = 1 Then
    Animate player, 1, 0.6, player_walk_back, 10.0
EndIf

If KeyHit(57) And jumping = False Then
    Animate player, 3, 0.5, player_jump, 5.0
    jumping = True
EndIf

; Animate player Idle
If walk = 0
    If start_idle = 1
        Animate player, 1, 0.6, player_idle1, 5.0
        start_idle = 0
    EndIf
EndIf

End Function

RasterRon commented:

How's it going Warren? It's been a while..

For the jumping, pretty much it's the same with other animation combination like walking and then idling.

As for the animation itself, I've seen jumping animation in 3 steps, start of jump, mid-air and landing. See Mixamo animations for example.

WazMeister commented:

Hi and Thanks.

I'm good, hope you are well.

I've see the Mixamo animations and still can't get mine to work, Wasted so much time tweaking, restarting and throwing code out the window.... I've managed to progress to have jump animation and jump mechanic work... but the jump mechnic is intermitten (i.e sometimes when holding forward it wont jump and have to tap space afew times.........) But most annoying is the walking or idle animation dont play if I jump and continue to hold forard once player lands it just stops all animation's until I nleg go of forward or back to reset it?

I beg, someone help before I crack my head on the wall (again!)

; Turn Left and Right
If KeyDown(d_key) Then
TurnEntity obj, 0, -2, 0
ElseIf KeyDown(a_key) Then
TurnEntity obj, 0, 2, 0
EndIf

; Walk Forwrd and Backward with animtion
If jumping = False And KeyHit(57)
    jumping = True
    anim = player_jump  
    Animate player, 3, 0.5, anim, 5.0
ElseIf KeyDown(w_key) Then
    MoveEntity obj, 0, 0, 0.7
    If anim <> player_walk Then
        anim = player_walk
        Animate player, 1, 0.7, anim, 10.0
    EndIf
ElseIf KeyDown(s_key) Then
    MoveEntity obj, 0, 0, -0.4
    If anim <> player_walk_back Then
        anim = player_walk_back
        Animate player, 1, 0.6, anim, 10.0
    EndIf
; Animate Idle if not moving
ElseIf anim <> player_idle1 Then
    anim = player_idle1
    Animate player, 1, 0.6, anim, 5.0
    anim_jumping = 0
EndIf

obj_x# = EntityX(obj):obj_z# = EntityZ(obj):obj_y# = EntityY(obj)

PlayerYVel# = PlayerYVel# - Gravity#

; If player is on the ground (i.e collided with the on the Plane Entity)
If EntityCollided(obj, 2) Then
    onground# = 1
    jumping = False
    PlayerYVel# = 0.0
EndIf

If jumping = True And onground = 1 Then
    PlayerYVel# = .85
    onground# = 0
EndIf

TranslateEntity player, 0, playerYVel#, 0

; Object hug the terrain (follow its heights) so dont run through it
If obj_y < TerrainY(land, obj_x, 0, obj_Z) Then
    PositionEntity obj, obj_x, TerrainY(land, obj_x, 0, obj_Z)+ 5, obj_z
EndIf
RasterRon commented:

you can also try hooking your animation triggers to collision and physics responses.

jump + y increase = jump up

y decrease or falling = landing anim.

if playing landing anim. + touch object or ground = idle anim.

RemiD commented:

@WazMeister >>
there is another way to animate 3d rigged skinned meshes, by setting the frames (poses), so that you can stop an animation which is currently playing, and start another one, and get the current frame (pose).

see this example : https://www.syntaxbomb.com/blitz2d-blitzplus-blitz3d/example-to-animate-a-rigged-skinned-mesh-with-specific-frames-without-animate/

This is to animate a rigged skinned mesh by setting the specific frame of the animation (between startframe and endframe), instead of using the animate() function

http://rd-stuff.fr/blitz3d/rigged-skinned-mesh-animation-using-setanimframe-201803251445.7z

The advantages are :
->you can load the same rigged skinned mesh, several times, so that it will have its own surface(s), and you don't need to extract all animations for each loaded mesh ... (useful for lighting shading with vertices colors)
->you can set the current anim frame of each mesh with an offset so that they will all animate differently (even if they are animating with the same animation)
->you can start / stop an animation exactly when you want, and start another, according to the "actionstate" of the entity
->you don't need to update the animated surfaces which are not in view and not visible...
->this simplifies the code because there are less things to check...

WazMeister commented:

Thanks Both.

That's a good point RasterRon.. I was wondering how to do that. How would someone check if increase or decrease of a variable? Assumints If <= 'n' etc?
Remi, thanks for link. Clicking it and then clicking link within it reports as a unsafe website?
https://www.syntaxbomb.com/blitz2d-blitzplus-blitz3d/example-to-animate-a-rigged-skinned-mesh-with-specific-frames-without-animate/

RemiD commented:

the 7z archive that i linked only contains a bb code example and a b3d mesh.

i often share code examples when i find them helpful...

do as you want !

Reply To Topic (minimum 10 characters)

Please log in to reply