Our teacher has asked to do a button for our app to jump and he has given us a reference:
He want us to use these formulas but we dont know how.
If anyone has any idea it would be very helpful.
fireboy_v4 (1).aia (2.3 MB)
PD: We are begginers and we dont know much about app inventor.
What's sen()?
Is it sine()?
Since you were given these formulas by the teacher, let's agree on what each symbol means.
-
t = time elapsed since launching the projectile, in seconds.
-
g = gravity, in meters per second squared ( 9.81 m/s² )
-
alpha (α) = the angle above horizontal of the launch, like a cannon. In AI2 that would be degrees, usually positive (unless you are digging a tunnel.)
-
v0 is the initial velocity
-
x is the horizontal displacement of the projectile in meters, at time t
-
y is the vertical displacement of the projectile, at time t
Please note that Canvas y values are reversed from math graph y values. Canvas graph ys start at the top and extend downwards.
The first equation (r,x,y,i) is unfamiliar and unnecessary.
Before I dive into your app, note that AI2 has a very nice graph component that would make this easy.
Before @ABG's answer it wasn't clear to me if:
- You are trying to code a game; you want to implement a jump for your character and you have asked to your teacher how to implement that ?
If this is the case, forget what he (the teacher) has said and learn what @marco_tanzi has linked in his previous post. That is far enough and easy to achieve to do what you want (in addition to the improvement in the smoothness of the jump as suggested by @Kevinkun ). - your teacher has explicitly asked you to implement the vectorial equation and he has told you the formulas that you have posted ? This is a completely different story: you have to code those formulas with the AI2 blocks, then you have to apply to your character to make it jumping. That is fairly more difficult, but @ABG has already suggested you another well working solution.
(Very often an easier solution is the best one)
Best wishes.
My last hint is: before you go on with further development, please try to don't use multiple screens (like scren1, screen2, screen3, and so on) but use virtual screens instead. If you use multiple screens, you will become crazy in passing variables across them and you will fight many other constraints. Therefore, search the forum for "virtual screens" or take a sight to my annexed example to see how virtual screens work.
MultipleScreenLittle.aia (849.0 KB)
Well, this is game physics, not Earth physics.
Your Screen is missing a Clock component, which is needed to apply the force of gravity over time.
You can find the Clock in the Sensors Drawer.
Besides what you were given earlier in this thread
there might be jumping samples in
Even in game physics, you need these concepts:
- Gravity changes the velocity of moving objects.
- velocity has two components, one for the x direction and the other for the y direction.
- velocity's x component tells how fast x changes over time
- velocity's y component tells how fast y changes over time.
- Gravity affects only the y velocity
- Gravity's effect is continuous, (a Clock Timer), except if the object is blocked by being on the ground (for example.)
Parabolic salto in Scratch
To translate Scratch into AI2, you would need to:
- Use a Clock Timer for the Wait block
- Replace the repeat loop with another fast Clock Timer, one iteration per Timer event.
Otherwise, it's nice.