# Help translating Python code to GDScript. Projectile trajectory.

Attention Topic was automatically imported from the old Question2Answer platform.

I’m wondering if anyone could help translate this python code for projectile motion into GDScript.

I’m trying to translate this to 2D, but I keep getting an error that "Invalid operands ‘Vector2’ and _____ in operator ‘+’. I get the issue of adding non vectors to vectors isn’t allowed, but wondering how to get around that and get something functioning.

Basically I want to be able to set the theta angle, ball.m(mass) and the ball.p(momentum vector) and then calculate the ball position x and y.

ground=box(pos=vector(0,-.2,0),size=vector(10,.4,2),color=color.green)
r0=ball.pos
g=vector(0,-9.8,0)
ball.m=0.2
v0=10
theta=70pi/180
ball.p=ball.m
v0*vector(cos(theta),sin(theta),0)

t=0
dt=0.001

while ball.pos.y>=0.1:
rate(1000)
Fnet=ball.mg
ball.p=ball.p+Fnet
dt
ball.pos=ball.pos+ball.p*dt/ball.m
t=t+dt

print(“dr final = “,ball.pos-r0,” m”)
print(“t final = “,t,” s”)

• Your code is not part of a function, use `func my_function():` to start a function declaration, and indent the code under it.
• You assign values to undeclared variables. This is forbidden. Use “var” to introduce new variables: `var r0 = ball.pos`.
If you want to add a float to each field of a Vector2, you could write `my_vector2 += Vector2(my_float, my_float)`.