0 votes

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 : https://ibb.co/ZWrcVYK

in Engine by (27 points)

1 Answer

+5 votes
Best answer

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():
    randomize()

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

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

        var tween = Tween.new()
        add_child(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)

        tween.start()

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.

by (10,483 points)
selected by

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.