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

#1 2011-11-23 10:22:03

flyby65
Scratcher
Registered: 2011-11-06
Posts: 4

Platform game help.

Can anyone tell me how to make sure a character can't go through walls even when there is gravity?

Offline

 

#2 2011-11-23 10:58:03

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: Platform game help.

You could use colour sensing. Make the sprite have a different colour on each side of it, then put this script:

When green flag clicked
Forever
If [colour of right side of sprite] is touching colour [wall colour] or  [colour of left side of sprite] is touching colour [wall colour]
Set 'X velocity' to ('X velocity'*-1)
End if
If [colour of top of sprite] is touching [wall colour]
Set 'Y velocity' to ('Y velocity*-1)
End if
If [colour of bottom of sprite] is touching [wall colour]
    If key up arrow pressed
    Set 'Y velocity to (how high you want the sprite to jump)
    Else
    Set 'Y velocity' to 1
Else
Change 'Y velocity' by -1
End if/else
End forever

I know this isn't that easy to understand, but I hope you get it!  smile


Why

Offline

 

#3 2011-11-23 12:16:49

flyby65
Scratcher
Registered: 2011-11-06
Posts: 4

Re: Platform game help.

thanks for the tip ill have to try it out

Offline

 

#4 2011-11-23 12:36:46

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: Platform game help.

Also, if you want your sprite to be just one colour, you can make a sprite called 'Sensor' almost exactly the same size as the sprite but one pixel wider in each direction and put the different colours on there. Then make it invisible by putting this on it:

When green flag clicked
Set 'ghost effect' to (100)

Then put the script I said in my previous post on the sensor, and then all you have to do is put this on the visible sprite:

When green flag clicked
Forever
Go to 'Sensor'
End forever

My game 'Scrolling Maze Game uses a 'Sensor' sprite, so if you're stuck you can download it from here, and look at the scripts.

wink


Why

Offline

 

Board footer