+2 votes

I want to build simple game like basketball. Is it possible to create projectile line like below image. I have searched all day, I have found draw arcs on Godot docs, but these arcs is part of a circle not a projectile line.
Here is what I want in this game:
https://play.google.com/store/apps/details?id=com.game.basketballshoot
enter image description here

asked Feb 23, 2017 in Engine by abalta (20 points)

1 Answer

+1 vote
Best answer

Sure, if you're talking about canvas drawing, it's the same concept. You calculate an array of points and draw lines between them.

extends Node2D

var points = Vector2Array()

func _ready():
    var position = Vector2(100, 500)
    var velocity = Vector2(10, -50)
    var gravity = Vector2(0, 20)

    var delta = .3

    for i in range(200):
        points.append(position)
        velocity.x *= .999
        velocity.y *= .991
        position += (velocity + gravity) * delta

var white = Color(1,1,1,1)
var red = Color(1,0,0,1)

func _draw():
    for i in range(0, points.size() - 1):
        draw_line(points[i], points[i+1], red, 3)
        draw_circle(points[i], 1, white)
answered Feb 24, 2017 by avencherus (4,817 points)
selected Feb 24, 2017 by abalta

Curve2D may help to make a more detailed curve but you will need to manage the bezier curve ins and outs on each point.

If you want some fancy looks, can be done with a polygon following positions too (is more work but you can assign a texture) or search the Q&A about trails, there is a plugin that can be used and modified to make permanent trails.

That is what I exactly want. Thank you. But, what is delta, and how can you find .999 and .991

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 How to use this Q&A? before posting your first questions.