- #1
AlbertRenshaw
- 14
- 0
Hello! I am a programmer and I am working on a video game, up until now I have used "gravity" to make objects fall just based off simple positioning code. I want to create realistic gravity code though!
Here is how the code works...
You simply create a variable and assign it a value..
ex. If I wanted to create a gravity constant I would say:
gravity = 5.485024534535
Now whenever I want to use this constant in my code / equations I will just type "gravity" instead of typing "5.485024534535"
You can set as many variables as you need..
I already have, height (the height of the object in the game), width (width in game), y (the y position (x-y cartesian coordinates) of the object, and a few other un-important things..
To set the y value of the ball you can say something like:
y = -50;
And the ball will move on the y-axis to -50 (coordinates of the top left corner of the screen = (0,0)
Dont worry about setting x-coordinate values in this code, it is falling in a straight path.
To define variables simply say:
variableName = variableNumber
I also have a function that is called every 0.01 seconds..
So inside this function if I were to say:
number1 = number1 + 5
and number1 starts out equal to 1, after 0.01 seconds it equals 1+5, another 0.01 seconds pass and it equals (1+5)+5, and so on.
Code should be in the following format:
{
Define variables here (each variable on a new line)
}
{{
stuff that happens every 0.01 seconds here
}}
Anyone up for the challenge?
Or even just want to help me understand how gravity works in moving things?
Here is how the code works...
You simply create a variable and assign it a value..
ex. If I wanted to create a gravity constant I would say:
gravity = 5.485024534535
Now whenever I want to use this constant in my code / equations I will just type "gravity" instead of typing "5.485024534535"
You can set as many variables as you need..
I already have, height (the height of the object in the game), width (width in game), y (the y position (x-y cartesian coordinates) of the object, and a few other un-important things..
To set the y value of the ball you can say something like:
y = -50;
And the ball will move on the y-axis to -50 (coordinates of the top left corner of the screen = (0,0)
Dont worry about setting x-coordinate values in this code, it is falling in a straight path.
To define variables simply say:
variableName = variableNumber
I also have a function that is called every 0.01 seconds..
So inside this function if I were to say:
number1 = number1 + 5
and number1 starts out equal to 1, after 0.01 seconds it equals 1+5, another 0.01 seconds pass and it equals (1+5)+5, and so on.
Code should be in the following format:
{
Define variables here (each variable on a new line)
}
{{
stuff that happens every 0.01 seconds here
}}
Anyone up for the challenge?
Or even just want to help me understand how gravity works in moving things?