No, really- my sprite is going too far into the ground/land because of the y velocity. When it finally touches land, it goes too far into the land and ends up being half above the land, and half below. Anyone know of a way to fix this?
Last edited by Sunrise-Moon (2010-08-04 15:54:01)
Offline
Perhaps change the script so the sprite falls down slower...
Offline
terminator68 wrote:
Perhaps change the script so the sprite falls down slower...
The problem is actually that 'Change Y by [yVel]' continues even if the sprite is touching land. I could fix it by getting a different system for gravity, like this one:
That'll make it change the y by -1 until it's touching the color, and it acts like:
If not touching color
Change y by -5
End if
Except of course, that it stops upon 1 pixel of contact. Should I sacrifice realistic jumping for working jumping?
Last edited by Sunrise-Moon (2010-08-04 16:05:37)
Offline
Sunrise-Moon wrote:
terminator68 wrote:
Perhaps change the script so the sprite falls down slower...
The problem is actually that 'Change Y by [yVel]' continues even if the sprite is touching land.
It's because when you use change Y by _, it jumps there, so like you said, it goes half in and then senses. There's no real way to fix it other than having it go slower, or making an invisible sprite to test ahead of the regular one.
Last edited by Harakou (2010-08-04 16:04:01)
Offline
Is the ground flat? If so, you could add something in script that checks to see if "Yvel" is greater than the distance to the ground. But beware, the "distance to" block calculates from the center of the sprite.
Offline
graham7sarah9 wrote:
Is the ground flat? If so, you could add something in script that checks to see if "Yvel" is greater than the distance to the ground. But beware, the "distance to" block calculates from the center of the sprite.
The level is flat, but the level is in teh backgroundz, so that won't quite work.
Last edited by Sunrise-Moon (2010-08-04 16:11:42)
Offline
Sunrise-Moon wrote:
graham7sarah9 wrote:
Is the ground flat? If so, you could add something in script that checks to see if "Y velocity" is greater than the distance to the ground. But beware, the "distance to" block calculates from the center of the sprite.
The level is flat, but the level is in the backgrounds, so that won't quite work.
I don't think scratch has a <distance to[ stage] block for the stage, but if there is would be one it would be the distance to the center, since its a scroller the sprite isn't really moving, the terrain is.
Last edited by jman13 (2010-08-04 16:24:19)
Offline
jman13 wrote:
Sunrise-Moon wrote:
graham7sarah9 wrote:
Is the ground flat? If so, you could add something in script that checks to see if "Y velocity" is greater than the distance to the ground. But beware, the "distance to" block calculates from the center of the sprite.
The level is flat, but the level is in the backgrounds, so that won't quite work.
I don't think scratch has a <distance to []> block for the stage, but if there is would be one it would be the distance to the center, since its a scroller the sprite isn't really moving, the terrain is.
That's what I meant. And by the way, this isn't a scroller- the levels stay still and stuff.
Offline
Offline
murpho wrote:
What if like you dont jump high enough. Youll get stuck in the middle of the thing you want to jump on
Eh?
Offline
murpho wrote:
Like hmm.... In some platformers on here if you dont get on top but half way through where you want to land you are in the middle of it
That can be fixed with sensors
Offline
If you want, I can give you a script for correct y movement. It even has velocity
Offline
terminator68 wrote:
If you want, I can give you a script for correct y movement. It even has velocity
![]()
Please do
Offline
Sunrise-Moon wrote:
graham7sarah9 wrote:
Is the ground flat? If so, you could add something in script that checks to see if "Yvel" is greater than the distance to the ground. But beware, the "distance to" block calculates from the center of the sprite.
The level is flat, but the level is in teh backgroundz, so that won't quite work.
Well just figure out the y position of the ground.
When green flag clicked Forever if not ((y postion + Yvel) < y position of ground) Change y by Yvel
Offline
Harakou wrote:
Sunrise-Moon wrote:
graham7sarah9 wrote:
Is the ground flat? If so, you could add something in script that checks to see if "Yvel" is greater than the distance to the ground. But beware, the "distance to" block calculates from the center of the sprite.
The level is flat, but the level is in teh backgroundz, so that won't quite work.
Well just figure out the y position of the ground.
Code:
When green flag clicked Forever if not ((y postion + Yvel) < y position of ground) Change y by Yvel
It won't work fast enough is the problem.
Offline
Sunrise-Moon wrote:
terminator68 wrote:
If you want, I can give you a script for correct y movement. It even has velocity
![]()
Please do
![]()
http://resources.scratchr.org/view/221. You may need to change the costumes .
Offline
terminator68 wrote:
Sunrise-Moon wrote:
terminator68 wrote:
If you want, I can give you a script for correct y movement. It even has velocity
![]()
Please do
![]()
http://resources.scratchr.org/view/221. You may need to change the costumes
.
That's what I was talking about with my script above^.
For now, I think it's impossible to fix my problem- I've tried everything (except the kitchen sink).
Offline
Sunrise-Moon wrote:
Harakou wrote:
Sunrise-Moon wrote:
The level is flat, but the level is in teh backgroundz, so that won't quite work.Well just figure out the y position of the ground.
Code:
When green flag clicked Forever if not ((y postion + Yvel) < y position of ground) Change y by YvelIt won't work fast enough is the problem.
Why not? It will go the same speed, but will check if it will go past the ground first.
Offline
Locomule wrote:
I'll fix it
Can you post a link to it here first though? I gotta go get my wife at work so I'll check for it when get back.
Here you go:
http://scratch.mit.edu/projects/Sunrise-Moon/1229445
Delete the sprite that is 'lol' when you download it- I only added it so the game would appear to be some stupid noob thing
Offline
Wow, so much struggling for such an simple problem. What happens when your sprite moves too far down (or any direction), you move it in the opposite direction, which in this case is up. The only problem now is telling the sprite when it is stuck in the ground, and for this I use sensor sprites.
I made a demo for this @ http://scratch.mit.edu/projects/archmage/101212
This is how I learned in flash, except in flash there is a command called a "hitTest" which lets you see if a sprite is in contact with a specific coordinate. Traditional games do not use an "Art Based" approach like scratch projects do. Instead all the information for the terrain, player and enemies are stored in Multi-dimentional arrays (simply lists of lists, think tables) and the game checks different values in the array to see if the player is hitting anything.
Last edited by archmage (2010-08-04 18:51:26)
Offline
Obviously any solution depends on your future plans. I'm assuming you will eventually have multiple maps with varying platform heights. I see you already have a sensor sprite started, is that the route you wanna take? Because if you are gonna make multiple, varied maps, the sensor sprite is a pretty easy and reliable way to go.
Offline