How to create bounce coins/loot in topdown 2d

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MasterRN

How to create bouncing coins (for example; from killing an enemy or opening a chest box) in a top down 2d game? I tried a few things liked the ridge body or adding random impulse but it’s not turning out right so I scrapped what I had. So I’m hoping someone can help me out here with the correct way to do it. Here is an example of what I want, I seen it on the Godot reddit : 167a5nrx4b-twitter-700x400 hosted at ImgBB — ImgBB

1 Like
:bust_in_silhouette: Reply From: njamster

I’m hoping someone can help me out here with the correct way to do it

There really isn’t a “correct way” - it all depends on what exactly you want to do.

Here is an example of what I want

When referencing someone else’s work, I think it’s only fair to give them proper credit. Also, as you already know who did what you want, why don’t you reach out to them on reddit or twitter and simply ask how the did it?

That being said, here’s a quick version I hacked together using Tweens:

extends Node2D

var COIN_SCENE = preload("res://Coin.tscn")

const MIN_X =  10.0
const MAX_X = 150.0
const MIN_Y = -80.0
const MAX_Y =  80.0

func _ready():

func _process(delta):
	if Input.is_action_just_pressed("ui_accept"):
		var coins = []

		for i in range(5):
			coins[i].position = Vector2(960, 540)

		var tween =

		for coin in coins:
			var direction = 1 if randi() % 2 == 0 else -1
			var goal = coin.position + Vector2(rand_range(MIN_X, MAX_X), rand_range(MIN_Y, MAX_Y)) * direction
			tween.interpolate_property(coin, "position:x", null, goal.x, 1, Tween.TRANS_LINEAR, Tween.EASE_IN)
			tween.interpolate_property(coin, "position:y", null, goal.y - 50, 0.4, Tween.TRANS_QUAD, Tween.EASE_OUT)
			tween.interpolate_property(coin, "position:y", goal.y - 50, goal.y, 0.4, Tween.TRANS_QUAD, Tween.EASE_IN, 0.4)
			tween.interpolate_property(coin, "position:y", goal.y, goal.y - 10, 0.1, Tween.TRANS_QUAD, Tween.EASE_IN, 0.8)
			tween.interpolate_property(coin, "position:y", goal.y - 10, goal.y, 0.1, Tween.TRANS_QUAD, Tween.EASE_IN, 0.9)

That’s probably not exactly (or even close to) how they did it for “Helms of Fury” and misses further details like rotating the coin or showing shadows on the ground, but it should give you a rough idea anyways. Getting those things “right” is a lot of work and usually the things you’ll spend the most time with when developing a game.

and how to reference the enemy position, when he dies?

liiao | 2020-12-20 17:17