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

#1 2012-02-17 11:15:27

MistralWing
Scratcher
Registered: 2012-02-17
Posts: 43

Help:Working walls

I've been working on a platform project recently and have never got this seemingly simple aspect to work properly:

when gf clicked
forever if <touching colour>?
move (-10) steps
The problem is, if the sprite is facing the wrong direction,he'll go flying through the wall instead-which defeats the purpose of a wall.
Any suggestions would be appreciated  smile

Offline

 

#2 2012-02-17 12:10:57

Targethero
Scratcher
Registered: 2008-09-08
Posts: 1000+

Re: Help:Working walls

One way to solve it:
If the wall is to the right of the character

when gf clicked
forever
 if <<key [key to make the sprite go right v] pressed ?> and <touching color [] ?>>
  change x by [-10]
If the wall is to the left of the character

when gf clicked
forever
 if <<key [key to make the sprite go left v] pressed ?> and <touching color [] ?>>
 change x by [10]

Last edited by Targethero (2012-02-17 12:19:29)


http://img97.imageshack.us/img97/3981/targethero2.png http://ls.gd/bo

Offline

 

#3 2012-02-17 13:55:40

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Help:Working walls

Yeah, using that script is the common method.

Another way, is to use sensors (basically another sprites which checks if it's touching a color then acts accordingly) to check if moving in that direction is possible.

The Sensor Sprite would look like this:
http://i1147.photobucket.com/albums/o549/Magnie/costume1.gif

when gf clicked
set [ghost v] effect to (100)
set [can_move_up v] to (1)
set [can_move_down v] to (1)
set [can_move_left v] to (1)
set [can_move_right v] to (1)
forever
    go to [Character v]
    if <color [#FF0000] is touching [#000000]?>
        set [can_move_up v] to (0)
    else
        set [can_move_up v] to (1)
    end

    if <color [#00FF00] is touching [#000000]?>
        set [can_move_down v] to (0)
    else
        set [can_move_down v] to (1)
    end

    if <color [#0000FF] is touching [#000000]?>
        set [can_move_left v] to (0)
    else
        set [can_move_left v] to (1)
    end

    if <color [#FFFF00] is touching [#000000]?>
        set [can_move_right v] to (0)
    else
        set [can_move_right v] to (1)
    end
Then the Character sprite:
http://wiki.scratch.mit.edu/images/Scratch_Cat.png
when gf clicked
forever
    if <<key [Up Arrow v] pressed?> and <(can_move_up) = (1)>>
        change y by (4)
    end

    if <<key [Down Arrow v] pressed?> and <(can_move_down) = (1)>>
        change y by (-4)
    end

    if <<key [Left Arrow v] pressed?> and <(can_move_left) = (1)>>
        change x by (-4)
    end

    if <<key [Right Arrow v] pressed?> and <(can_move_right) = (1)>>
        change x by (4)
    end
Edit: Updated sensor sprite costume since the old one broke.

Last edited by Magnie (2012-10-26 12:22:53)

Offline

 

#4 2012-02-17 17:02:54

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Help:Working walls

@Magnie - You might want to mention that the sensor sprite is set to 100% ghost so that it can still sense...but is invisible.  It is also then usually chained to the character sprite with  a forever loop and a Goto

when gf clicked
set [ghost v] effect to (100)
forever 
    goto [character_sprite v]
end


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#5 2012-02-17 17:24:55

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Help:Working walls

Paddle2See wrote:

@Magnie - You might want to mention that the sensor sprite is set to 100% ghost so that it can still sense...but is invisible.  It is also then usually chained to the character sprite with  a forever loop and a Goto

when gf clicked
set [ghost v] effect to (100)
forever 
    goto [character_sprite v]
end

Yeah, no worries, I had already added it to the script.  smile

Offline

 

#6 2012-02-19 13:41:47

MistralWing
Scratcher
Registered: 2012-02-17
Posts: 43

Re: Help:Working walls

Thank you all;it works much better now!

Offline

 

#7 2012-03-31 22:26:09

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

Re: Help:Working walls

Consider trying...

when gf clicked
forever
 if <key [right arrow v] pressed?>
  change [xvel v] by (1)
 end
 if <key [left arrow v] pressed?>
  change [xvel v] by (-1)
 end
 set [xvel v] to ((xvel) * (.87))
 change x by (xvel)
 if <touching [level v]?>
  change y by (([abs v] of (xvel)) + (1))
  if <touching [level v]?>
   change y by ((0) - (([abs v] of (xvel)) + (1)))
   change x by ((0)-(xvel))
   set [xvel v] to ((xvel) / (2))
  end
 end  
 if <key [up arrow v] pressed?>
  change y by (-1)
  if <touching [level v]?>
   set [yvel v] to (10)
  end
  change y by (1)
 end
 if <(yvel) < [3]>
  change y by (-1)
  if <not<touching [level v]?>>
   change [yvel v] by (-1)
  end
  change y by (1)
 end
 set [yvel v] to ((yvel) * (0.9))
 change y by (yvel)
 if <touching [level v]?>
  change y by ((0) - (yvel))
  set [yvel v] to ((yvel) / (2.5))
 end
end

Offline

 

#8 2012-08-02 17:10:13

titaniumstudios
New Scratcher
Registered: 2012-08-02
Posts: 10

Re: Help:Working walls

wow nice
___________________________________________________________________________________
check this out http://scratch.mit.edu/forums/viewtopic.php?pid=1340669#p1340669
our thread

Offline

 

#9 2012-10-26 14:52:11

Friddle16
Scratcher
Registered: 2012-08-21
Posts: 100+

Re: Help:Working walls

Wow! I Am going to use the sensor method!


http://oi46.tinypic.com/21c78yw.jpg

Offline

 

#10 2013-02-20 14:18:58

breenworks
New Scratcher
Registered: 2011-10-05
Posts: 3

Re: Help:Working walls

I find this thread EXTREMELY helpful!  Thank you.

Offline

 

#11 2013-03-27 16:54:44

Jinx98_test
Scratcher
Registered: 2012-05-14
Posts: 4

Re: Help:Working walls

The Jumping sprite the sensor can tell if the block is right above it or not. So here is a scenario that i am having trouble with. I press the jump button(w) and the sensor sprite does not see any blocks above it, and there aren't so it jumps. But, if the block is a little ways above the sensor sprite, the sensor wont see it so it thinks it clear. Then the sprite jumps and goes through the block above it. How do you make it so, it will still jump, but when it hits something it will bounce back down instead of go through it? Here is the project that I'm making that I'm have this problem with if you want to actually see it for your self  wink   http://beta.scratch.mit.edu/projects/10093309/
Thanks,

      ~Jinx,

Last edited by Jinx98_test (2013-03-27 16:58:19)

Offline

 

Board footer