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

#1 2009-02-11 15:16:44

doctorgoo
Scratcher
Registered: 2009-02-10
Posts: 8

need help with gravity

hello

i am making a halo game and i really need help with grav.

when i jump ON TO a box its fine but after that when i walk off the side of the box i just float at the same hight as the b0x.

if some1 could give me a script for gravity that would let me fall to my original height when i fall off the box i would be so grateful!

ty

Last edited by doctorgoo (2009-02-11 15:20:54)

Offline

 

#2 2009-02-11 15:20:39

mrweston
Scratcher
Registered: 2007-12-13
Posts: 100+

Re: need help with gravity

Essentially, you want to have a script that is constantly making the sprite fall (changing its y by a negative amount), except at the times when it's touching something solid. Simple example:

forever if (not <touching [ground]>) {
    change y by (-1)
}

Last edited by mrweston (2009-02-11 15:22:09)

Offline

 

#3 2009-02-11 15:25:34

doctorgoo
Scratcher
Registered: 2009-02-10
Posts: 8

Re: need help with gravity

hmm the problem is that messes up with my walking and jumping!

Offline

 

#4 2009-02-11 15:29:06

mrweston
Scratcher
Registered: 2007-12-13
Posts: 100+

Re: need help with gravity

How so? Might need to use a variable or two to get it to only activate the gravity when not doing those things:

When Space key pressed {
    set $jumping to (1)
    broadcast Jump and wait
    set $jumping to (0)
}

forever if (not <touching [ground]>) AND ($jumping = 0) {
    change y by (-1)
}

Or something like that.

Last edited by mrweston (2009-02-11 15:30:08)

Offline

 

#5 2009-02-11 15:32:51

doctorgoo
Scratcher
Registered: 2009-02-10
Posts: 8

Re: need help with gravity

hmm ill explain my whole game to you just to make shure

you start off just standing there and there are lots of black items you can drag and drop to make your own level

i have sorted out making them solid but i need to fall off them when i walk off them

(if you play halo 3 you wil know what forge is, well this is a scratch version of it)

Offline

 

#6 2009-02-13 02:31:29

yambanshee
Scratcher
Registered: 2007-11-06
Posts: 500+

Re: need help with gravity

are they all the same colour? if so, simply have something looking like this
forever{
if (touching colour (select colour)){
grav = 0
} else {
change grav by -1
}
if(Key up Arrow is pressed){
if(grav = 0){
grav = 5
}
}
change y by grav
}

Offline

 

#7 2009-02-14 12:29:16

doctorgoo
Scratcher
Registered: 2009-02-10
Posts: 8

Re: need help with gravity

god i  so confused...

Last edited by doctorgoo (2009-02-14 13:01:43)

Offline

 

#8 2009-02-15 14:46:06

shadowwarrior77
Scratcher
Registered: 2008-03-28
Posts: 6

Re: need help with gravity

Here, download this http://scratch.mit.edu/projects/shadowwarrior77/417818 and take a look at its scripting, then just use it...its pretty simple and its great!

Also, you can change how high and how fast he falls by changing the Yvelocity

It should work, just make sure to put a black outline on everything you want the sprite to walk on or land on  smile

Enjoy,
   -Shadow

Offline

 

#9 2009-02-15 14:48:03

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: need help with gravity

For super simple gravity & movement look here
http://scratch.mit.edu/projects/archmage/72848


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#10 2009-02-16 14:22:36

DarthPickley
Scratcher
Registered: 2008-06-13
Posts: 100+

Re: need help with gravity

you need to have a sprite, a color, or maybe a function that can be sensed so that you can sense whether or not you are touching a "floor".  If what you really want is true GRAVITY you need some advanced physics, which would mean you need velocity. you can have a yvel variable and change y by yvel. I'm not sure how you are sensing whether you are touching a box... I wouldn't know the best way to do t so that it worked with your current scripts. I would need an example of it.

Offline

 

#11 2009-02-17 06:22:35

doctorgoo
Scratcher
Registered: 2009-02-10
Posts: 8

Re: need help with gravity

ty so much shadow warrior

it worked i will be posting my game soon!

Offline

 

Board footer