I want to make an animation like the one showed in the video
I want the animation to speed up or down with velocity, such that it ends just before the landing.. however when jumping up, the player is not able to complete the animation. The only way by which I think this can be done is by using the formula time = distance/speed and change speed_scale accordingly. Nut I have been unable to calculate it since velocity is always changing
Any ideas how to go about this? Here is my code
extends CharacterBody2D
const SPEED = 300.0
const JUMP_VELOCITY= -500.0
var anim : AnimationPlayer
@export var gravity : float = ProjectSettings.get_setting("physics/2d/default_gravity")
func _ready():
anim = $AnimationPlayer
func _physics_process(delta):
_calculate_movement(delta)
move_and_slide()
func _calculate_movement(delta:float):
if not is_on_floor():
#Change speed_scale with velocity
anim.speed_scale = abs(velocity.y/100)
velocity.y += gravity * delta
if Input.is_action_just_released("jump") and velocity.y<0.0:
velocity.y += 100
elif Input.is_action_just_pressed("jump"):
anim.play("Rotate")
velocity.y = JUMP_VELOCITY
var direction = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
if direction != 0:
velocity.x = SPEED * direction
~~else:
velocity.x = lerp(velocity.x,0.0,0.1)