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

#1 2012-06-09 21:17:05

zubblewu
Scratcher
Registered: 2011-02-17
Posts: 1000+

Slope detection

My platformer engine has perfect collisions as of now, but no slope detection. You can view it here. If anyone could add a slope detection/movement section to the script, I would be grateful.


........................................................................................................................................................................................................................................

Offline

 

#2 2012-06-10 09:49:24

Randomno
Scratcher
Registered: 2012-06-04
Posts: 39

Re: Slope detection

There are no slopes, though.


http://img209.imageshack.us/img209/5524/randomno.png
I do stuff with stuff. I also stuff stuff.

Offline

 

#3 2012-06-10 11:53:46

zubblewu
Scratcher
Registered: 2011-02-17
Posts: 1000+

Re: Slope detection

Because there is no slope detection XD


........................................................................................................................................................................................................................................

Offline

 

#4 2012-06-10 13:17:20

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Slope detection

Use two sensor colours on the bottom edges of the sprite (they don't have to be very different from the sprites natural colour) and use

when gf clicked
set [unsure] to (1)
forever
  if <<color [#FF0000] is touching [#000000]?> and <not<color [#FFFFFF] is touching [#000000]?>>>
    if <(unsure) = (1)>
      switch to costume (relevant costume)
      set [unsure v] to (0)
and you just dupe that code, it basically detects what corners are touching what and switches costume/direction accordingly, (unsure) is to detect if it's already set, thereby stopping it flickering. Unsire would need to be reset whenever you're not touching a platform. Oh BTW this only works for 45 135 etc degrees


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#5 2012-06-10 14:59:40

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Slope detection

I made a project that shows how to do it:http://scratch.mit.edu/projects/zammer990/2601498


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#6 2012-06-10 15:10:03

zubblewu
Scratcher
Registered: 2011-02-17
Posts: 1000+

Re: Slope detection

Yes, I know how to do that. I mean the one costume 45 degrees or less kind of slope detection. And instead of using costumes and sensors, you can just have it switch to a tiny slope detection costume, say a few pixels, and duplicate something like
[if<touching color black>]
[change y by(insert number here)]
[change [direction^] by (insert number here)]

Then, do the same for the other side, then do that for

[if<not<touching color black>>]
[change y by (-insert number)]
[change [direction^] by (insert number)]

Thn add all those up and average them together. I think that's what you mean sort of but that's not
What I'm trying to do.


........................................................................................................................................................................................................................................

Offline

 

#7 2012-06-10 15:14:50

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Slope detection

You can't do that easily, perhaps if you had a variable for each platform with it's direction and match it you could

EDIT:
a way of doing it:

when gf clicked
point in direction (wanted direction)

when gf clicked
forever
if <touching [sprite v]?>
point in direction ([direction v] of [sprite v])

Last edited by zammer990 (2012-06-10 15:18:59)


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#8 2012-06-10 15:17:36

zubblewu
Scratcher
Registered: 2011-02-17
Posts: 1000+

Re: Slope detection

But it's an engine  tongue . It's supposed to be a base you build upon. And that script might take 15-30 minutes to get right and perfect.


........................................................................................................................................................................................................................................

Offline

 

#9 2012-06-10 15:18:53

zubblewu
Scratcher
Registered: 2011-02-17
Posts: 1000+

Re: Slope detection

I saw your project. And I'll go write a quick script.

Edit: This could take a while, it'll probably involve a lot of trig

Last edited by zubblewu (2012-06-10 15:24:19)


........................................................................................................................................................................................................................................

Offline

 

#10 2012-06-10 15:37:38

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Slope detection

zubblewu wrote:

I saw your project. And I'll go write a quick script.

Edit: This could take a while, it'll probably involve a lot of trig

unlikely, trigonometry is totally unnecessary, id't just be either sensors or variables


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#11 2012-06-10 15:43:58

zubblewu
Scratcher
Registered: 2011-02-17
Posts: 1000+

Re: Slope detection

I mean with moving based on the slope. You'll see when i finish it.


........................................................................................................................................................................................................................................

Offline

 

#12 2012-06-10 16:52:21

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Slope detection

zubblewu wrote:

I mean with moving based on the slope. You'll see when i finish it.

What v = r*w?
velocity = distance to contact point * angular velocity


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#13 2012-06-10 16:55:14

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Slope detection

And this is why I recommended array-based platforming.  Slope detection is basically done for you; that is, the programmer can specify the exact shape of each type of tile.  If I had  finished the platforming base in that project I linked you to, I would have implemented 34 different tiles (including more sloped surfaces, and even rounded ones), but I ran out of time/energy/enthusiasm/Squeak's memory.

Offline

 

#14 2012-06-10 17:16:08

zubblewu
Scratcher
Registered: 2011-02-17
Posts: 1000+

Re: Slope detection

amcerbu wrote:

And this is why I recommended array-based platforming.  Slope detection is basically done for you; that is, the programmer can specify the exact shape of each type of tile.  If I had  finished the platforming base in that project I linked you to, I would have implemented 34 different tiles (including more sloped surfaces, and even rounded ones), but I ran out of time/energy/enthusiasm/Squeak's memory.

Yep. What I mean, though, is using arctangent to predict the direction based on the slope, and changing the xvel by the cosine of the direction, creating realistic slope physics. I would have finished it in a few minutes but my frien and I are going to a concert and didn't have a chance to finish the last bit and test it. I'll probably post it at about 10 or 11 or sometime tomorrow.


........................................................................................................................................................................................................................................

Offline

 

#15 2012-06-10 19:59:16

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Slope detection

But it's not quite just about changing x-velocity by cosine of direction.  You actually don't need any trig at all.  Check out Slopes, a project I made a few months ago that does what I think you're looking for.  It takes in a slope value (from a list of slopes where it has approximated the slope of the tangent line of a function at many points), and gives bouncing/rolling physics, depending on the value of restitution; set it to 0 for sliding.  Friction could also be easily added, I just never got around to it.

Last edited by amcerbu (2012-06-10 19:59:47)

Offline

 

#16 2012-06-10 23:16:34

chanmanpartyman
Scratcher
Registered: 2011-05-30
Posts: 500+

Re: Slope detection

Judging by the scripts it is capable to go up a 45 degree angle.

Offline

 

#17 2012-06-10 23:40:40

zubblewu
Scratcher
Registered: 2011-02-17
Posts: 1000+

Re: Slope detection

chanmanpartyman wrote:

Judging by the scripts it is capable to go up a 45 degree angle.

It seems like it should, but when I tested it it didn't work. If you want you can add a slope and see what happens XD.


........................................................................................................................................................................................................................................

Offline

 

#18 2012-06-11 18:47:59

zubblewu
Scratcher
Registered: 2011-02-17
Posts: 1000+

Re: Slope detection

Bump. And please ignore the rest of the posts.


........................................................................................................................................................................................................................................

Offline

 

#19 2012-06-14 21:11:12

berberberber
Scratcher
Registered: 2012-03-08
Posts: 1000+

Re: Slope detection

My project perfect platformer base has perfect movement based on slopes.  Test out the scripts and let me know!


http://i47.tinypic.com/2iaa73k.png

Offline

 

Board footer