+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:
enter image description here

in Engine by (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):
        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)
by (5,206 points)
selected by

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.
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.