From Test-Scratch-Wiki

Revision as of 21:41, 12 June 2016 by InterwikiBot (talk | contribs) (Uploading Page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Translate: - English 
DocumentInQuestion.png It has been suggested that this page's contents be merged with the page Simulating Gravity. You can discuss this on the page's talk page.

With the right backdrop and scripts, programming a sprite to "fly" may be fairly simple, but adding gravity helps with making platformers as well as jetpack games. The following script can help with the gravity implementation in a flying engine:[factually inaccurate?]

when green flag clicked
forever
  if <key [space v] pressed?> then//You're flying
    glide (0.4) secs to: x: (x position) y: ((y position) + (40))
  else//You're falling
    glide (0.4) secs to: x: (x position) y: (-110)

Or you can simply use Velocity:

when green flag clicked
forever
  if <key [space v] pressed?> then
    change [Y Velocity v] by (0.1)
  else
    if <(Y Velocity) > (-8)>//Maximum falling speed
      change [Y Velocity v] by (-0.1)//Gravity
    end
    if <touching [ground v]?> then //A ground sprite
      set [Y Velocity v] to (0)
    end
  end
  change y by (Y Velocity)

Example Projects

The following projects are examples of the above or a similar engine:

See Also