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

#1 2012-08-03 10:18:10

whiteflame115
New Scratcher
Registered: 2012-07-29
Posts: 7

How to make sprite move up diagonal line

I am playing around with a platform game (really just experimenting to see how things work) and I am trying to get a ball sprite to move up a diagonal line.

I have all my lines in a single sprite and I use the touching sensor to know when the ball sprite touches the line sprite. 

If the ball sprite isn't touching the line sprite the ball starts to fall until it lands on the line sprite again.

But I can't get the sprite to move up a diagonal line.

Offline

 

#2 2012-08-03 10:52:23

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

Re: How to make sprite move up diagonal line

change x by (10)
change y by (10)


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

Offline

 

#3 2012-08-03 10:59:47

whiteflame115
New Scratcher
Registered: 2012-07-29
Posts: 7

Re: How to make sprite move up diagonal line

zammer990 wrote:

change x by (10)
change y by (10)

Well, umm, yeah that much I know.  LOL!  It's the sensing part that I am having difficulty with.

All of the lines are in a single sprite and I want another sprite to follow the lines.

It works when the line is diagonal but as soon as the line is diagonal it stops.

Offline

 

#4 2012-08-03 11:58:04

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: How to make sprite move up diagonal line

Let me help:

when gf clicked
forever
 if <touching [line v]?>
  change x by (1)
  change y by (1)
 else
  change y by (-1)//[Or whatever you use for gravity.]
 end
I hope that this helps!

Last edited by ErnieParke (2012-08-03 12:00:34)


http://i46.tinypic.com/35ismmc.png

Offline

 

#5 2012-08-03 13:08:06

whiteflame115
New Scratcher
Registered: 2012-07-29
Posts: 7

Re: How to make sprite move up diagonal line

Hey Ernie,

I don't think that will work with the way I have the game set up.

I've uploaded the example if you would be willing to take a look.

http://scratch.mit.edu/projects/whiteflame115/2711883

Thanks a bunch.

Steve
(itek5bux aka whiteflame115's dad)

Offline

 

#6 2012-08-03 13:22:24

whiteflame115
New Scratcher
Registered: 2012-07-29
Posts: 7

Re: How to make sprite move up diagonal line

*epiphany*

Ernie your suggestion worked once I started over and built the logic around your code example.

Thanks!

Offline

 

#7 2012-08-03 16:15:17

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: How to make sprite move up diagonal line

whiteflame115 wrote:

*epiphany*

I never heard of that word. Let me look it up...

whiteflame115 wrote:

Ernie your suggestion worked once I started over and built the logic around your code example.

Thanks!

Your welcome! I like to help scratchers, which is what I did to you!

Just curious, is the uploaded version of your project the most up to date one? If it isn't, then can you tell me when you'll update it? And when you do, could you give me a link? Thanks.

Anyway, this is what I've found for epiphany on Dictionary.com:

Dictionary.com wrote:

e·piph·a·ny
   [ih-pif-uh-nee]

noun, plural e·piph·a·nies.

Cutting part of it out...

3. A sudden, intuitive perception of or insight into the reality or essential meaning of something, usually initiated by some simple, homely, or commonplace occurrence or experience.

4. A literary work or section of a work presenting, usually symbolically, such a moment of revelation and insight.

I think that you were using definition 3.

Last edited by ErnieParke (2012-08-03 16:19:25)


http://i46.tinypic.com/35ismmc.png

Offline

 

#8 2012-08-03 16:40:59

BirdByte
Scratcher
Registered: 2012-07-07
Posts: 1000+

Re: How to make sprite move up diagonal line

I believe you are looking for slope detection, which is a very valuable skill when making a platformer. I'm really surprised that the wiki has no article on it.

Basically you want something like this:

forever
 if <key [right arrow v] pressed?>
  change x by (2)
  if <touching [ground v]?>
   change y by (4)
   if <touching [ground v]?>
    change y by (-4)
   else
    change y by (-2)
   end
  end
 end
end


http://i50.tinypic.com/312u714.jpg

Offline

 

#9 2012-08-03 17:25:45

maxamillion321
Scratcher
Registered: 2011-06-17
Posts: 500+

Re: How to make sprite move up diagonal line

You use this.

go to x:(0)y:(0)

Last edited by maxamillion321 (2012-08-03 17:26:18)

Offline

 

#10 2012-08-03 17:29:37

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: How to make sprite move up diagonal line

For your sensor, you'll need to follow these steps:

1). Pick five different colors.

2). Find and copy the sprite that you want the sensor for.

3). Go and edit the 2nd copied sprite.

4). While in paint editor, use four of the five colors to create a box around the sprite. Use one color per side, and leave out the corners. Also, make the box's lines several pixels thick.

5). Pick your 5th color and make a line below, but touching, the bottom side of the box.
An example of this type of sensor can be viewed in The Dangerous Adventure, which I created to help shrey15 with sensing and moving platforms.

6). Delete everything except for the lines you had drawn earlier.

Now, put this script in the sensor:

When gf clicked
hide//Or you can use [set [ghost effect v] to (100)].
forever
 go to [tennis ball v]
 if < color [ ] is touching color [black]?>// Color of the top part of the box.
  set [up v] to (0)
 else
  set [up v] to (1)
 end
 if < color [ ] is touching color [black]?>// Color of the left part of the box.
  set [left v] to (0)
 else
  set [left v] to (1)
 end
 if < color [ ] is touching color [black]?>// Color of the right part of the box.
  set [right v] to (0)
 else
  set [right v] to (1)
 end
 if < color [ ] is touching color [black]?>// Color of the 2nd to bottom line of box.
  set [down 1 v] to (0)
 else
  set [down 1 v] to (1)
 end
 if < color [ ] is touching color [black]?>// Color of the bottom line of the box.
  set [down 2 v] to (0)
 else
  set [down 2 v] to (1)
 end
Some of the comments kept on getting cut off, so I had to shorten them considerably.

Anyway, add this to the tennis ball:

when gf clicked
forever
 if <<key [up arrow v] pressed?> and <<(up) = (1)> and <(down 2) = (0)>>>
  Whatever script you use to jump.
 end
 if <(down 2) = (1)>
  change y by (-1)
 end

when gf clicked
forever
 if <(down 1) = (0)>
  change y by (1)
 end
 if <<key [left arrow v] pressed?> and <(left) = (1)>>
  change x by (-1)
 end
 if <<key [right arrow v] pressed?> and <(right) = (1)>>
  change x by (1)
 end
The comments on the script don't seem to be appearing, so here they are:
The first if is for jumping, the second if is for moving up slopes and not falling through moving platforms, the third if is for moving left, and the fourth if is for moving left. The fifth is for gravity.

I hope that this helps to improve your game!

Last edited by ErnieParke (2012-08-05 13:22:38)


http://i46.tinypic.com/35ismmc.png

Offline

 

Board footer