Pages: 1
Topic closed
I'm trying to perfect velocity and gravity scripts in a scrolling program.
What it does right now is changes the y position by 1 if you are touching the terrain sprites. This, however, is not fast enough, where a mountain comes out of the sprite, and then you slowly glide up the side of the mountain. Please help!
This is my currrent script (I couldn't get some parts to work correctly):
when gf clicked set [bounce? v] to (0) set [scrollX v] to (0) set [xvel v] to (0) set [yvel v] to (0) set [gravity v] to (0) forever set [xvel v] to <(xvel)*(0.95)> set [yvel v] to <(yvel)*(0.95)> if <key [up arrow v] pressed?> change [yvel v] by (1) end if <key [left arrow v] pressed?> change [xvel v] by (-1) turn ccw(15) degrees end if <key [right arrow v] pressed?> change [xvel v] by (1) turn cw(15) degrees end if < <not <([abs v] of <(x position) - (normalx)>) < [11]> > or < <> or <> > > <((scrollX)+(xvel)) < [0]> <((scrollX)+(xvel)) > ((480)*((z.terrs)-(1)))> Read the comment >>>// These above go in the empty "or" block 2above. if < not <([abs v] of ((xpositon) + (xvel))) > [199] > > change x by (xvel) end else change [scrollX v] by (xvel) set x to (normalx) end change y by ((yvel)-(gravity)) if <not < <touching [Terrain1 v]?> or <touching [Terrain2 v]?> >> change [gravity v] by (0.1) if <(gravity) > [1.2]> set [bounce? v] to (1) end else set [gravity v] to (0) change y by (1) if <(bounce) = [1]> change [yvel v] by ((0.3) * (gravity)) set [bounce v] to (0) end end endAny suggestions?
Last edited by LiquidMetal (2012-04-05 12:05:27)
Offline
I didn't look at your script, but I'm commenting for when it is finished. Working with slants has always been a challenge. I do have one question though: by "realistic physics" do you want the sprite, when it hits slanted ground, to bounce at an angle, or can it simply bounce up and down as it would on flat ground? Or do you not want the sprite to bounce at all and simply land on the ground?
Offline
I want the yvel to bounce. The xvel value will still be the same, so it will still move right/left as well.
Last edited by LiquidMetal (2012-04-05 09:51:56)
Offline
Well, I'm on a computer without Scratch right now, but here's what I have:
You want to check if there is a wall/slant before you move someplace. Something like
if <key [right arrow v] pressed?> change x by ((xvel)+(1)) if<touching [terrain v]?> check if it is a slant or a wall else change [xvel v] by [1] end change x by ((-1)-(xvel)) endTo check if it is a slant or a wall try something like this:
change y by (3) // move up if<touching [terrain v]?> // wall change x by ((-1)-(xvel)) // bounce off wall set [xvel v] to [0] // kill x velocity else // slant change y by (2) // move up slope end change y by (-3) // counter act original ySomething like that should do it.
Last edited by MoreGamesNow (2012-04-05 17:02:57)
Offline
I tried that:
1) it made the sprite slower on a slant
2) when I turned the other direction quickly, I wound up going the wrong way - into the wall. (b/c the x velocity was greater then 1)
Offline
Ok, message received. Still on a non-Scratch machine unfortunately
Offline
Try putting a "change [xvel] by [1]" in the else statement of the slant/wall script. That should change the slowness.
Maybe replace "set [xvel] to [0]" with "set [xvel] to ( (-1) * (xvel) ) for the second one?
Last edited by MoreGamesNow (2012-04-06 08:36:19)
Offline
Topic closed
Pages: 1