Hi,
I was playing around with jumping of characters of the examples. I want to create a better feeling/looking jump physics instead of giving the character just an impuls and wait what will happen. I splitted the inair part in two sections and modified the body gravity in the parts:
1) movement up
2) movement down
In addition I put in the possiblility to give the character a higher jump if a long press is done
3) movement up is haveing two body gravity values
When the player is pressing we don't know if this will be only a short press or a long press, therefore we cannot use a different impuls value for a low or high jump. So we change the gravity underway.
Finally I came up with the attached Test.
I was playing around with jumping of characters of the examples. I want to create a better feeling/looking jump physics instead of giving the character just an impuls and wait what will happen. I splitted the inair part in two sections and modified the body gravity in the parts:
1) movement up
2) movement down
In addition I put in the possiblility to give the character a higher jump if a long press is done
3) movement up is haveing two body gravity values
When the player is pressing we don't know if this will be only a short press or a long press, therefore we cannot use a different impuls value for a low or high jump. So we change the gravity underway.
Finally I came up with the attached Test.
B4X:
Public Sub Tick (GS As X2GameStep)
' push the ball if pressed
If x2.mGame.Jump = True Then
x2.mGame.Jump = False
bw.Body.ApplyLinearImpulse(x2.CreateVec2(0, impulsValue), bw.Body.Position)
x2.SoundPool.PlaySound("wing")
End If
'
' ******************************************************************
' * Modify the BodyGravity for nicer Jumps *
' * *
' * 1) jump upwards and downwards have different Gravity settings *
' * 2) shot press done with normal Gravity = normal jumps *
' * 3) long press done Gravity will be lower = higher jumps *
' * *
' ******************************************************************
'
' Gravity normal = normal jump hight
bw.mWorld.Gravity.Set(0,-10)
'
If bw.Body.LinearVelocity.Y < 0 Then ' are in up- or down direction?
' body is in falling direction = raise of Gravity
bw.mWorld.Gravity.Set(0 , bw.mWorld.Gravity.Y * fallMultiplier)
'
Else if bw.Body.LinearVelocity.Y > 0 And (x2.mGame.Up = False) Then ' in up-direction and long pressing
' Gravity lower = higher Jump
bw.mWorld.Gravity.Set(0 , bw.mWorld.Gravity.Y / highJumpMultiplier )
Else
' non of all = normal Gravity remains (this if-part can be removed)
End If
'
bw.Body.LinearVelocity = x2.CreateVec2(0, Min(4, bw.Body.LinearVelocity.Y))
'
If GS.ShouldDraw Then
bw.UpdateGraphic(GS, True)
End If
End Sub
[code]
Attachments
Last edited: