0
\$\begingroup\$

With the following code, I either get a straight line or no line at all. I have tried almost the same thing in Unity and I get something that looks like orbiting, but here I get nothing.

How can I fix my code to draw a trajectory?

func _update_trajectory(delta):
    line.clear_points()
    var line_points = []
    var pos = mousePosition
    
    #starting velocity 200 for now
    var xAxis=200
    var yAxis =200
    
    var vel = Vector2(0,100)
    var vecR = sunGravity.position-pos
    var gravityForce = (vecR).normalized()
    var angle= 0
    
    
    var lastPos = pos +velocity.normalized()
    for i in range(1,MAX_POINTS-1):
        line_points.append(pos)
        
        vel+=Rigidbody_test(pos)
        lastPos=pos
        pos += vel*delta
        
    line.points=line_points 

func Rigidbody_test(pos1:Vector2):
   var planetPos = sunGravity.position
   var dir=planetPos-pos1
   var dis = dir.length_squared()
   var forceMag=2*g_constant*((sunGravity.mass*currentMass)/dis)
   var force =dir.normalized()*forceMag
   return force
\$\endgroup\$
1
  • \$\begingroup\$ It looks like your last edit introduced an error - you start the _update_trajectory function, but the lines under it are not indented as expected (or you're missing the pass statement). Regarding the problem, how are you drawing line? Does the inspector show the contents/points of the line changing? \$\endgroup\$
    – Pikalek
    Commented Jan 4, 2023 at 19:25

1 Answer 1

0
\$\begingroup\$

I have fixed my issue by increasing gravity constant so instead of having 0.0006 or whatever I just increased it to something like 274 which actually showed the curvature.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .