# Godot 4, using raycast2d to draw a circle out of curve2d points

Attention Topic was automatically imported from the old Question2Answer platform.

Im making a magic game in godot 4 and am using a path2d and pathfollow2d to make spell paths. for one of these spell trajectories, I need the spell to orbit around the player, so I have this code

extends CharacterBody2D

var orbit = Curve2D.new()
for x in range(0, 360):
spellraycast.set_global_rotation(x)
spellpath.set_curve(orbit)

I’m not sure what the question is here?

jgodfrey | 2023-03-06 04:05

Sorry, I forgot to ask the question :(, it doesn’t work for some reason. The ray just shows up pointing at the bottom left and no points are created. I don’t know what I’m doing wrong or if this method just doesn’t work

AI_notFound | 2023-03-06 12:46

You’re using a ray cast to do what now?
That’s pretty much overkill

Math is the solution here

extends CharacterBody2D

# adds points to curve2D in a circle
# - center: the center point of the circle
# - radius: controls the size of the circle
# - points: the amount of points to add to the curve2D
func set_spell_path(curve: Curve2D, center: Vector2, radius: float, points: int):
for i in range(points +1):
# Calculate the angle for this point on the circle
var angle = (i / float(points)) * TAU
# Calculate the x and y coordinates of the point on the circle
var x = center.x + radius * cos(angle)
var y = center.y + radius * sin(angle)
# Add the point to the curve