2d projectile line

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By abalta
:warning: Old Version Published before Godot 3 was released.

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:

enter image description here

:bust_in_silhouette: Reply From: avencherus

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)

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.

eons | 2017-02-24 14:58

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

abalta | 2017-02-24 17:33