Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | directive0 |
I have a game with a solar system. It has planets rotating around the sun.
I’d really like to have the orbit of whatever target is selected to be defined by a 2d circle that is drawn in realtime.
So far I am able to get the coordinates of my target object (lets say the earth) and the coordinates of the center of my solar system and I feed those into a circle drawing function that someone offered in a post here to write a function that draws the circle.
So great. Now I can draw a circle. Only problem is when I try to draw them and I zoom in and out I get this:
Here’s my code:
extends Node2D
var camera
var radius
var center
# class member variables go here, for example:
# var a = 2
# var b = "textvar"
func _ready():
# get my camera
camera = get_tree().get_root().get_node("Node").get_node("Camera")
# get the target to be the radius of the circle
var target = get_parent().get_node("target_reticule").get_position()
radius = target
# this is where the center of my solar system is.
center = Vector3(0,-100,0)
func _draw():
draw_orbit()
func draw_orbit():
# pointless shuffling.
var radius2d = radius
# get the location onscreen of the object I want to trace an orbit for.
var center2d = camera.unproject_position(center)
draw_empty_circle(center2d,radius2d,Color(1,1,1,1),1,3)
func draw_empty_circle(circle_center, circle_radius, color, resolution, thick):
var draw_counter = 1
var line_origin = Vector2()
var line_end = Vector2()
line_origin = circle_radius + circle_center
while draw_counter <= 360:
line_end = circle_radius.rotated(deg2rad(draw_counter)) + circle_center
draw_line(line_origin, line_end, color, thick)
draw_counter += 1 / resolution
line_origin = line_end
line_end = circle_radius.rotated(deg2rad(360)) + circle_center
draw_line(line_origin, line_end, color, thick)
func _process(delta):
#update values every cycle.
var target = get_parent().get_node("target_reticule").get_position()
radius = target
update()
Can anyone tell me what the heck I’m doing wrong?
Sooo. Why are using a 3D camera in a 2D scene? I can’t really watch video since I’m on mobile data so I can’t tell.
edit: nevermind I can watch it. But still. Why does it need to be both 2D and 3D?
SIsilicon | 2018-05-24 18:23
The scene is 3d only overlay elements like reticules, control panels and indicators are 2d. The reason for this is so I can make 3d assets (far easier to make for me) and take advantage of 3d dynamic lighting.
I want to draw a circle over a 3d scene that is representative of the position of 3d objects in 3d space. It would be kind of unwieldy to use a 3d mesh to represent this so I am opting to use a 2d circle instead.
If your suggestion is to just use 2d that’s fine, and I am considering it,but I can’t believe the behaviour I’m experiencing fromy set up is expected so I am asking if anyone can offer guidance as to why this is happening and help me fix it.
directive0 | 2018-05-24 22:16