Movement Bounce

Godot Version

godot 4.7.2.stable

Question

I want to add some bounce when moving my character but i don’t know how?

extends CharacterBody2D

@onready var BodySprite = $AnimatedSprite2D

const SPEED = 300.0

var input: Vector2

func get_input():
	input.x = Input.get_action_strength("Right") - Input.get_action_strength("Left")
	input.y = Input.get_action_strength("Down") - Input.get_action_strength("Up")
	return input.normalized()

func _physics_process(delta: float) -> void:
	var playerInput = get_input()
	velocity = playerInput * SPEED
	move_and_slide()

	if playerInput == Vector2.ZERO:
		BodySprite.play("Idle")
	elif abs(playerInput.x) > abs(playerInput.y):
		BodySprite.play("Walk_Sides")
		BodySprite.flip_h = playerInput.x < 0
	elif playerInput.y > 0:
		BodySprite.play("Walk_Down")
	else:
		BodySprite.play("Walk_Up")

What kind of bounce do you mean? The sprite bobbing up and down or something like that?
Mostly asking because it can mean several things to my knowledge :stuck_out_tongue:

its kinda like bobbing when moving

There are like a handful of ways you could do it, you could make an animation using the animation player to have that character move however you like, then you play said animation while the character is moving on loop.

Or what I’d do personally is use Tweens for something like this, you should take a peep they’re Very useful for animations imo.

Alright! i will give it a try :slight_smile:

What I’d do is like, animate the scale, rotation, x and y for the sprite using a tween for whatever duration you want, each at a different time to create a nice loop, for instance, my character rotates left and right slightly for a duration of 1 second. Then it goes up and down by offsetting the Y offset every 0.5 or 0.25 seconds so it bounces accordingly to the tilts, then you can match a squash and stretch scaling to the same duration of the Y offset… All of this with tweens, I’d recommend toying around with them for a while to see how they work.