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

#1 2012-07-16 01:08:36

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

For Luxturna

Luxturna said he needed some help for his game, so I'm going to give her a guide.
So, he needed help with sensing on his platformer:
   Sensing is difficult, especially since Scratch does not support atomocity. There are many ways to do it efficiently, but the one thing that will glitch so much is: color sensors. The main problem is you go through walls because: the colors on the costume are too thin and it gets through the wall or the whole thing goes into the wall and it get's stuck. So basically, color sensing is off the list.
   However, there are still many other methods, such as the reliable (but tacky and annoying) wall colors. Technically this is still color sensing but more efficient. You also have the most efficient method on Scratch, various versions have been made by me, eRKSToCK, RHY3756547, Rahi-Tak, and Kileymeister. This is what it's all about. Basically when it hits the level sprite, or the basic layout of the sprite, it checks the terrain. It can be: a horizontal wall, a vertical wall, or a 45° slope. So first we will check for a slope (assuming you are using velocities):

change x by (xvel)
if <touching [level v]?>
 change y by (([abs v] of (xvel)) + (1))
end
What this does is it checks for collision, and if it collides with a wall, it reacts to it as if it were a slope. This works because it take the absolute value (abs, always positive) of the x velocity and changes the y position by it, but plus one more to be safe. This way it travels up a 45° slope.
Now we need to check if it's a wall:
change x by (xvel)
if <touching [level v]?>
 change y by (([abs v] of (xvel)) + (1))
 if <touching [level v]?>
  change x by ((xvel) * (-1))
  change [xvel v] by ((xvel) / (-2))
end
Now we have checked for wall collisions and avoided getting stuck. But we still need to enable y collisions. Se first we'll do jumping, add this after the x collision script, but keep it in the same loop:
if <key [up arrow v] pressed?>
 change y by (-3)
 change y by (3)
end
Now your probably asking if I'm drunk. I'm just getting you comfortable with the style. Basically what it's going to do is go down 3 pixels, check for collisions, and move back up. If it hits the floor, that means it can jump, you get it?
if <key [up arrow v] pressed?>
 change y by (-3)
 if <touching [level v]?>
  set [yvel v] to (10)
 end
 change y by (3)
end
Now jumping still won't work, because nothing is commanding it to. Now we'll get to collisions and coming back down.
if <key [up arrow v] pressed?>
 change y by (-3)
 if <touching [level v]?>
  set [yvel v] to (10)
 end
 change y by (3)
end
change y by (-3)
if <not <touching [level v]?>>
 change [yvel v] by (-1)
end
change y by (3)
Now it goes back down, but it still needs to move.
if <key [up arrow v] pressed?>
 change y by (-3)
 if <touching [level v]?>
  set [yvel v] to (10)
 end
 change y by (3)
end
change y by (-3)
if <not <touching [level v]?>>
 change [yvel v] by (-1)
end
change y by (3)
change y by (yvel)
Okay, now collisions.
if <key [up arrow v] pressed?>
 change y by (-3)
 if <touching [level v]?>
  set [yvel v] to (10)
 end
 change y by (3)
end
change y by (-3)
if <not <touching [level v]?>>
 change [yvel v] by (-1)
end
change y by (3)
change y by (yvel)
if <touching [level v]?>
 change y by ((yvel) * (-1))
 change [yvel v] by ((yvel) / (-2))
end
That should work, just make sure you've also implemented a good x moving system. I don't wanna give it all to ya'.

Last edited by chanmanpartyman (2012-07-17 17:52:31)

Offline

 

#2 2012-07-16 01:33:39

Luxturna
Scratcher
Registered: 2011-04-24
Posts: 38

Re: For Luxturna

Thanks! And thanks for not giving me everything. Now I know not to use color sensing. how did you do the blocks? and I'm a girl, btw  tongue


http://scratch.mit.edu/static/icons/buddy/782569_med.png?t=2012-03-10+00%3A38%3A57

Offline

 

#3 2012-07-16 16:00:14

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

Re: For Luxturna

Luxturna wrote:

Thanks! And thanks for not giving me everything. Now I know not to use color sensing. how did you do the blocks? and I'm a girl, btw  tongue

Oh, sorry. You do the blocks with the [scratchblocks] tag.

Last edited by chanmanpartyman (2012-07-16 16:00:26)

Offline

 

#4 2012-07-16 22:52:17

Luxturna
Scratcher
Registered: 2011-04-24
Posts: 38

Re: For Luxturna

It doesn't work. I'm falling through the ground. Help. I re-uploaded with the changes.


http://scratch.mit.edu/static/icons/buddy/782569_med.png?t=2012-03-10+00%3A38%3A57

Offline

 

#5 2012-07-16 23:29:58

thebriculator
Scratcher
Registered: 2011-07-11
Posts: 500+

Re: For Luxturna

color sensing does work, as you can switch to a "sensor" costume at the top of  the loop, switch back to the regular costume at the bottom and it works out fine. I learned it from thesuperguidegames' Paper Mario a while back.


.     http://tiny.cc/2cwgpw    http://tiny.cc/viwgpw    http://tiny.cc/iwwgpw

Offline

 

#6 2012-07-17 17:49:45

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

Re: For Luxturna

thebriculator wrote:

color sensing does work, as you can switch to a "sensor" costume at the top of  the loop, switch back to the regular costume at the bottom and it works out fine. I learned it from thesuperguidegames' Paper Mario a while back.

Which is color sensing, that's what I meant, and what I used in my final Egg game, the one that was the scroller. If you look at it you can see how efficient that was. Now compare it to 2030, which is the project I developed this method on. The collision barely have any glitches, and the glitches is has only effects it visually, it still runs normal.

Offline

 

#7 2012-07-17 17:53:43

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

Re: For Luxturna

Luxturna wrote:

It doesn't work. I'm falling through the ground. Help. I re-uploaded with the changes.

Try redoing the scripts. I also noticed just by playing it there was no decay on your velocity. Try and put the line:

set [xvel v] to ((xvel) * (0.87))

Offline

 

#8 2012-07-17 20:43:25

Luxturna
Scratcher
Registered: 2011-04-24
Posts: 38

Re: For Luxturna

do i do the same for y? because i'm not falling.


http://scratch.mit.edu/static/icons/buddy/782569_med.png?t=2012-03-10+00%3A38%3A57

Offline

 

#9 2012-07-17 22:06:46

thebriculator
Scratcher
Registered: 2011-07-11
Posts: 500+

Re: For Luxturna

chanmanpartyman wrote:

thebriculator wrote:

color sensing does work, as you can switch to a "sensor" costume at the top of  the loop, switch back to the regular costume at the bottom and it works out fine. I learned it from thesuperguidegames' Paper Mario a while back.

Which is color sensing, that's what I meant, and what I used in my final Egg game, the one that was the scroller. If you look at it you can see how efficient that was. Now compare it to 2030, which is the project I developed this method on. The collision barely have any glitches, and the glitches is has only effects it visually, it still runs normal.

true, your 2030 and 2031 do have great physics.  smile
as a side note, are you ever going to finish 2031?

Last edited by thebriculator (2012-07-17 22:06:59)


.     http://tiny.cc/2cwgpw    http://tiny.cc/viwgpw    http://tiny.cc/iwwgpw

Offline

 

#10 2012-07-18 00:28:46

Luxturna
Scratcher
Registered: 2011-04-24
Posts: 38

Re: For Luxturna

hehe i forgot the <not > block.


http://scratch.mit.edu/static/icons/buddy/782569_med.png?t=2012-03-10+00%3A38%3A57

Offline

 

#11 2012-07-18 23:53:22

Luxturna
Scratcher
Registered: 2011-04-24
Posts: 38

Re: For Luxturna

is there any way to make it less bouncy?


http://scratch.mit.edu/static/icons/buddy/782569_med.png?t=2012-03-10+00%3A38%3A57

Offline

 

Board footer