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

#1 2009-12-26 09:01:37

Chatter
Scratcher
Registered: 2009-11-29
Posts: 500+

How to make a character move (for a game)

This is a forum on how to make your characters move for a game. Let's get started.

Let's say you want the character to move with the arrow keys. That takes four scripts.

1.      <when[  up arrow  ]key pressed>
         <point in direction(  0 
         <move( 10  )steps>
         <stop script>

2.       <when[  down arrow  ]key pressed>
         <point in direction(  180
         <move( 10  )steps>
         <stop script>

3.       <when[  right arrow  ]key pressed>
         <point in direction(  90
         <move( 10  )steps>
         <stop script>

4.       <when[  left arrow  ]key pressed>
         <point in direction(  -90 or 270
         <move( 10  )steps>
         <stop script>

Notes: Your character doesn't have to move ten steps, that depends on how fast you want it to move. If you want your character to only move left and right, that will take only two scripts and you will have to take away the up arrow script and the down arrow script.

Let's say you don't want your character to move with the arrow keys, but follow the mouse. That is very simple to do. It takes a single script. Here's the script:

<when green flag clicked>
<forever>
<go to[  mouse-pointer
<end>

Now you know how to make characters move for your game! A game is not a game when you can't move the characters, right? Enjoy programming your game! I hope it will work well! Please read: In the projects you made with the help of this forum, please give me a bit of credit because you learned to do it here and please post a link, if you don't know how to link please go to my other forum called "How to link".

I hope you guys have learned something from this forum!  big_smile

~ From me, Chatter


http://img19.imageshack.us/img19/2339/mcdonaldsjoke.gifAll your problems are like batter when you add a little Chatter, because when you have Chat, you're safe from bats.  big_smile
"And so?" - The little people in my brain|Status: Snow in April?

Offline

 

#2 2009-12-26 22:57:36

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: How to make a character move (for a game)

Looking for an alternate method?

Try this!

<when green flag clicked>
<forever>
<if><key[ rightarrow ]pressed?>
<change x by( positive number
<if><key[ leftarrow ]pressed?>
<change x by( negative number
<if><key[ uparrow ]pressed?>
<change y by( positive number
<if><key[ downarrow ]pressed?>
<change y by( negative number

Another method looks like this. It is similar to the second method Chatter posted, but it makes the characters follow the mouse rather than go to it.

<when green flag clicked>
<forever>
<point in direction( mouse pointer
<move( a number! )steps>

Last edited by shadow_7283 (2009-12-26 22:58:11)

Offline

 

#3 2009-12-27 09:46:01

Buggy132k9
Scratcher
Registered: 2009-12-19
Posts: 19

Re: How to make a character move (for a game)

To make it follow mouse when clicked...

<when green flag clicked>
<forever>
<wait until> <mouse down?>
<point towards( Mouse pointer
<move( positive number! )steps>

This is fun!

Offline

 

#4 2009-12-27 11:25:16

Chatter
Scratcher
Registered: 2009-11-29
Posts: 500+

Re: How to make a character move (for a game)

Well it is very good programming, but i want to start with something simple for new
Scratchers, like shorter scripts, if you understand. No offence, it's really good.  smile


http://img19.imageshack.us/img19/2339/mcdonaldsjoke.gifAll your problems are like batter when you add a little Chatter, because when you have Chat, you're safe from bats.  big_smile
"And so?" - The little people in my brain|Status: Snow in April?

Offline

 

#5 2009-12-27 11:26:56

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: How to make a character move (for a game)

I don't know. These all contribute, and at some point or another they are going to want an alternative method of movement (in some areas, your's are kind of limited).

Offline

 

#6 2009-12-27 11:37:36

Buggy132k9
Scratcher
Registered: 2009-12-19
Posts: 19

Re: How to make a character move (for a game)

And Chatter, just pointing out to every newbie who wants to make a shooter game (like me  tongue  ) :
Chatters moving method won't work for it, you'll want to use a move x/y positive/negative so you don't have to look where your going.
Seriously, try it, if your pointing at mouse, it makes movement jumpy (it keeps changing where its facing) and may shoot in the wrong direction.

Learnt that the hard way...

Offline

 

#7 2009-12-27 12:36:06

Chatter
Scratcher
Registered: 2009-11-29
Posts: 500+

Re: How to make a character move (for a game)

This one is for other games, not really shooting games. For help with those games, please go to another universe.  smile  I'm not into making those games. And also the thing shows you how it's going to rotate, you're supposed to click the 'Don't rotate' button.

~ Chatter


http://img19.imageshack.us/img19/2339/mcdonaldsjoke.gifAll your problems are like batter when you add a little Chatter, because when you have Chat, you're safe from bats.  big_smile
"And so?" - The little people in my brain|Status: Snow in April?

Offline

 

#8 2009-12-27 15:00:37

MrMunchkin
Scratcher
Registered: 2009-05-16
Posts: 86

Re: How to make a character move (for a game)

mm another way is to 'when right arrow key pressed, change x by 5' and 'when left arrow key pressed, change x by -5' etc. this can be easier and smoother.


http://scratch.mit.edu/projects/MrMunchkin/958570 http://scratch.mit.edu/projects/MrMunchkin/1074952
Check Them Out!

Offline

 

#9 2009-12-27 21:48:37

Chatter
Scratcher
Registered: 2009-11-29
Posts: 500+

Re: How to make a character move (for a game)

MrMunchkin wrote:

mm another way is to 'when right arrow key pressed, change x by 5' and 'when left arrow key pressed, change x by -5' etc. this can be easier and smoother.

Let's just say there is a million possibilities.  smile


http://img19.imageshack.us/img19/2339/mcdonaldsjoke.gifAll your problems are like batter when you add a little Chatter, because when you have Chat, you're safe from bats.  big_smile
"And so?" - The little people in my brain|Status: Snow in April?

Offline

 

#10 2009-12-27 22:41:32

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: How to make a character move (for a game)

I definitely think that all movement should be through the

<change x by(
<change y by(
<set x to(
<set y to( 
It is good for practice in the future. I don't even know why the Scratch team included

the <move( -- )steps> block. When users become more advanced, they will find this block more and more difficult to work with.

Last edited by shadow_7283 (2009-12-27 22:42:54)

Offline

 

#11 2009-12-28 06:01:24

Buggy132k9
Scratcher
Registered: 2009-12-19
Posts: 19

Re: How to make a character move (for a game)

shadow_7283 wrote:

I definitely think that all movement should be through the

<change x by(
<change y by(
<set x to(
<set y to( 
It is good for practice in the future. I don't even know why the Scratch team included

the <move( -- )steps> block. When users become more advanced, they will find this block more and more difficult to work with.

QFT.

Move steps is really annoying, and if you start off with a program thats getting a bit too advanced for a newbie; learning by using move steps will waste loads of time when you realise that a lot of stuff is smoother and easier with change x/y

Offline

 

#12 2009-12-29 20:47:01

itchyone
Scratcher
Registered: 2009-08-15
Posts: 100+

Re: How to make a character move (for a game)

one thing with the

<move(    )steps>
[/blocks]
is that it can let you move in a non- standard direction(diagonal, for instance)

Last edited by itchyone (2009-12-29 20:47:53)


Build your own platformer with BYOP!
Want to test some highly dangerous Wormholes? For science?

Offline

 

#13 2009-12-30 08:37:03

Buggy132k9
Scratcher
Registered: 2009-12-19
Posts: 19

Re: How to make a character move (for a game)

Hmmm, i guess so, but if theres a border you must keep your character in then move steps will let it escape.

Offline

 

Board footer