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

#1 2010-06-06 05:11:00

WhiteStone
Scratcher
Registered: 2010-06-04
Posts: 7

How do you keep a sprite on a moving platform?

I have a script for this, but it makes it shake very obviously, AND I can't make the sprite jump off of it without screwing up the script and making the sprite eventually fall. Just so you know, I'm using the "y velocity" variable for jumping. So here's the script I used:

<when green flag clicked>
<forever>
<if><< <touching[ Platform 3 <and> <( <{ y velocity }> <<> -1 )> >>
<set{ y velocity }to( 0
<if><key[ up arrow ]pressed?>
<set{ y velocity }to( 15
<end>
<forever if><< <touching[ Platform 3 <and> <( <{ y velocity }> <<> -1 )> >>
<set y to( (( y position of Platform 3 <+> 35 ))
<end>
So it's supposed to make the sprite jump, but that doesn't work because of the last command which is to set the sprites y position to that of Platform 3. So what else should I use instead of that? And how can I stop it from shaking the sprite?

Last edited by WhiteStone (2010-06-06 05:15:54)

Offline

 

#2 2010-06-06 08:51:33

Greentabby55
Scratcher
Registered: 2010-05-04
Posts: 50

Re: How do you keep a sprite on a moving platform?

When Green Flag Clicked
Forever
If Touching Sprite1
Set Y to Y position
Set X to X position

If you don't add "Forever" in there, it will only work for the first millisecond of the game.

Offline

 

#3 2010-06-06 08:52:43

Greentabby55
Scratcher
Registered: 2010-05-04
Posts: 50

Re: How do you keep a sprite on a moving platform?

@My Last Post

Oh, I'm sorry. I read it wrong. I might be able to help you later.

Offline

 

#4 2010-06-06 14:10:52

colorfusion
Scratcher
Registered: 2009-10-03
Posts: 500+

Re: How do you keep a sprite on a moving platform?

Forever if <touching [moving platform]>
Set [X velocity/momentum] to (Platform Momentum)
Set [Y momentum] to 0
Change y by 1

And on the moving platform

Forever
Set [Platform momentum] to 5
Repeat 10
Move 5 steps

Set [Platform momentum] to -5
Repeat 10
Move -5 steps

Offline

 

#5 2010-06-07 02:36:27

WhiteStone
Scratcher
Registered: 2010-06-04
Posts: 7

Re: How do you keep a sprite on a moving platform?

Yeah, that doesn't really work since I have the gravity going forever... I'm sure there's a way to work around that, but I'd like help in figuring that out.

Offline

 

#6 2010-06-07 13:09:51

JSO
Community Moderator
Registered: 2007-06-23
Posts: 1000+

Re: How do you keep a sprite on a moving platform?

Hi, I made this for you ;D
It doesn't work online but It does offline.
Check it out: http://scratch.mit.edu/projects/JSO/1105685


http://oi48.tinypic.com/2v1q0e9.jpg

Offline

 

#7 2010-06-10 00:29:46

WhiteStone
Scratcher
Registered: 2010-06-04
Posts: 7

Re: How do you keep a sprite on a moving platform?

Awesome! Thanks a bunch!

But the problem is now that the jumping works strangely, and your script causes the y velocity to go to 0 as soon as it touches the platform. I guess that's easy to fix though, I could make it so that the sprite can only stop moving if its y velocity is less than 0.

The other problem is that I want to keep the sprite on top of the platform. Since y velocity continually decreases by 1, the y position of the sprite decreases by 1, 2, 3, 4, 5, 6, 7.... and so on. So that causes the sprite to not stop directly on top of the platform. This is easy to solve for stationary platforms such as the ground, but I'm not sure how to do that for moving ones.

Actually, I think I'll post my project to show you how it works. There are some useless scripts that I was playing around with to try and get some things to work... but they didn't. So I hope you could look over those and see what's wrong with them as well as finding a way to solve this problem...

Anyways, your contribution was extremely helpful! Thanks again!

Offline

 

#8 2010-06-10 13:06:51

JSO
Community Moderator
Registered: 2007-06-23
Posts: 1000+

Re: How do you keep a sprite on a moving platform?

The Moving Platform scripts works separately from the platformer script, you can use it with any other platformer script. I just used archmage's for ease.

Please upload yours ^^


http://oi48.tinypic.com/2v1q0e9.jpg

Offline

 

#9 2010-06-11 05:05:02

WhiteStone
Scratcher
Registered: 2010-06-04
Posts: 7

Re: How do you keep a sprite on a moving platform?

Just uploaded it. Please check it out and help, that would be awesome!

Offline

 

#10 2010-06-11 14:00:15

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: How do you keep a sprite on a moving platform?

I don't really have time right now to help you,
but i suggest you have a look at one of the greatest velocity scripts, Chop Shop.

If that still doesn't help enough, reply to me and i'll provide you with a special project for you.

Hope it helps!  smile

Offline

 

Board footer