This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-06-29 20:28:06

skippito
Scratcher
Registered: 2012-03-17
Posts: 100+

Gravity

Here is a script for realistic jumping using gravity:

when gf clicked
set [Gravity v] to [0]
repeat [however long you want it to repeat]
  if <touching color [color of ground]>
    set [Gravity v] to [0]
    change y by [1]
    set [Gravity v] to [the larger this number is, the higher your sprite will jump]
  else
    change [Gravity v] by [-1]
    change y by (Gravity)
  end
end

Offline

 

#2 2012-06-30 02:02:38

daniel_j
Scratcher
Registered: 2012-05-22
Posts: 100+

Re: Gravity

nice script! but I am thinking this is the wrong forum for this, why not try the requests forum!  big_smile


http://i50.tinypic.com/2dhgnsx.jpg

Offline

 

#3 2012-06-30 03:15:38

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: Gravity

Nice script! Although I recommend Velocity for gravity. It's much more smooth.


Hai.

Offline

 

#4 2012-06-30 08:06:23

skippito
Scratcher
Registered: 2012-03-17
Posts: 100+

Re: Gravity

fg123 wrote:

Nice script! Although I recommend Velocity for gravity. It's much more smooth.

This is the same as y velocity. I just used the variable "gravity" in case people became confused.

Offline

 

#5 2012-06-30 13:21:07

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: Gravity

skippito wrote:

fg123 wrote:

Nice script! Although I recommend Velocity for gravity. It's much more smooth.

This is the same as y velocity. I just used the variable "gravity" in case people became confused.

I see, but usually, instead of changing gravity by -1, we use:

This gives a smooth decline too.

set [gravity v] to ((gravity) * (0.95))

Last edited by fg123 (2012-06-30 13:21:55)


Hai.

Offline

 

#6 2012-06-30 23:44:44

DragonLoverGirl
Scratcher
Registered: 2012-05-12
Posts: 7

Re: Gravity

skippito wrote:

Here is a script for realistic jumping using gravity:

when gf clicked
set [Gravity v] to [0]
repeat [however long you want it to repeat]
  if <touching color [color of ground]>
    set [Gravity v] to [0]
    change y by [1]
    set [Gravity v] to [the larger this number is, the higher your sprite will jump]
  else
    change [Gravity v] by [-1]
    change y by (Gravity)
  end
end

I used this and the sprite kept ending up staying in the air after it jumped... did i do something wrong? I copied exactly..

Last edited by DragonLoverGirl (2012-06-30 23:45:13)

Offline

 

#7 2012-07-01 02:35:56

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: Gravity

DragonLoverGirl wrote:

skippito wrote:

Here is a script for realistic jumping using gravity:

when gf clicked
set [Gravity v] to [0]
repeat [however long you want it to repeat]
  if <touching color [color of ground]?>
    set [Gravity v] to [0]
    change y by [1]
    set [Gravity v] to [the larger this number is, the higher your sprite will jump]
  else
    change [Gravity v] by [-1]
    change y by (Gravity)
  end
end

I used this and the sprite kept ending up staying in the air after it jumped... did i do something wrong? I copied exactly..

You want to make sure that the

repeat
end [however long you want it to repeat]
is changed to a
forever
end
.

Last edited by fg123 (2012-07-01 02:36:13)


Hai.

Offline

 

#8 2012-07-02 13:27:25

CoDpRo43000
Scratcher
Registered: 2012-06-30
Posts: 4

Re: Gravity

hey i have a velocity script in my game that if you press dont press the button that makes you jump, it will bring you down gradually faster instead of staying the same speed while falling. i can post the script itself if you want me to?

Offline

 

#9 2012-07-02 13:46:28

CoDpRo43000
Scratcher
Registered: 2012-06-30
Posts: 4

Re: Gravity

oops sorry but why does it bounce like that?

Offline

 

Board footer