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

#1 2009-07-18 08:31:08

dusski
Scratcher
Registered: 2009-06-04
Posts: 75

direction moving towards how to

i want to know how to using arrows rotate sprite and when i click up arrow sprite moves in that direction? is there a script which i could use from some game or something?
PLZ help


dusski

Offline

 

#2 2009-07-18 08:47:07

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: direction moving towards how to

i think what you want is:

Code:

<when green flag clicked>
<forever>
<if><key[ up ] keypressed>
<point in direction( 0 
<end>
<if><key[ left ] key pressed>
<point in direction( -90
<end>

so on


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#3 2009-07-18 09:26:12

dusski
Scratcher
Registered: 2009-06-04
Posts: 75

Re: direction moving towards how to

I'll try that but i don't say it's not that


dusski

Offline

 

#4 2009-07-18 09:33:07

dusski
Scratcher
Registered: 2009-06-04
Posts: 75

Re: direction moving towards how to

no it's not that
more ideas


dusski

Offline

 

#5 2009-07-18 10:04:57

The-Whiz
Scratcher
Registered: 2007-07-09
Posts: 1000+

Re: direction moving towards how to

All right:

Code:

/^^^^^^^^^^^^^^^\_____
[When flag clicked____]
[forever]
[][if <key [right arrow] pressed?>]
[][][turn [5] degrees right]
[][end of if______________________]
[][if <key [left arrow] pressed?>]
[][][turn [5] degrees left]
[][end of if_____________________]
[][if <key [up arrow] pressed?>]
[][][move [5] steps]
[][end of if___________________]
[end of forever]

Last edited by The-Whiz (2009-07-18 10:06:17)

Offline

 

#6 2009-07-18 15:32:18

dusski
Scratcher
Registered: 2009-06-04
Posts: 75

Re: direction moving towards how to

The-Whiz wrote:

All right:

Code:

/^^^^^^^^^^^^^^^\_____
[When flag clicked____]
[forever]
[][if <key [right arrow] pressed?>]
[][][turn [5] degrees right]
[][end of if______________________]
[][if <key [left arrow] pressed?>]
[][][turn [5] degrees left]
[][end of if_____________________]
[][if <key [up arrow] pressed?>]
[][][move [5] steps]
[][end of if___________________]
[end of forever]

ok that works but i need this too:
when i click left or right arrow my sprite makes a full circle but i don't want my sprite to do that. I want to go as far as 45 degrees left and right. How can I do that?


dusski

Offline

 

#7 2009-07-18 15:37:22

The-Whiz
Scratcher
Registered: 2007-07-09
Posts: 1000+

Re: direction moving towards how to

Yes...

Code:

/^^^^^^^^^^^^^^^\_____
[When flag clicked____]
[forever]
[][if <key [right arrow] pressed?>]
[][][turn [5] degrees right]
[][end of if______________________]
[][if <key [left arrow] pressed?>]
[][][turn [5] degrees left]
[][end of if_____________________]
[][if <key [up arrow] pressed?>]
[][][move [5] steps]
[][end of if___________________]
[][if <(direction) > (45)>]
[][][point in direction (45)]
[][end of if_____________________]
[][if <(direction) < (-45)>]
[][][point in direction (-45)]
[][end of if_____________________]
[end of forever]

That should work.

Offline

 

#8 2009-07-18 15:50:32

dusski
Scratcher
Registered: 2009-06-04
Posts: 75

Re: direction moving towards how to

how can i make a sprite fall? For example i fly with a rocket an i let go up arrow whit is gaining trust and i "fall". How can i do that?


dusski

Offline

 

#9 2009-07-18 15:56:57

The-Whiz
Scratcher
Registered: 2007-07-09
Posts: 1000+

Re: direction moving towards how to

Ok this is getting complicated...

Code:

/^^^^^^^^^^^^^^^\_____
[When flag clicked____]
[forever]
[][if <key [right arrow] pressed?>]
[][][turn [5] degrees right]
[][end of if______________________]
[][if <key [left arrow] pressed?>]
[][][turn [5] degrees left]
[][end of if_____________________]
[][if <key [up arrow] pressed?>]
[][][move [5] steps]
[][end of if___________________]
[][if <(direction) > (45)>]
[][][point in direction (45)]
[][end of if_____________________]
[][if <(direction) < (-45)>]
[][][point in direction (-45)]
[][end of if_____________________]
[][if <key [up arrow] pressed?]
[][][change (Y-vel) by 1]
[][else]
[][][change (Y-vel) by -1]
[][end of if_________________]
[][change y by (Y-vel)]
[end of forever]

Last edited by The-Whiz (2009-07-18 15:57:56)

Offline

 

#10 2009-07-18 16:35:16

billyedward
Scratcher
Registered: 2008-01-03
Posts: 500+

Re: direction moving towards how to

markyparky56 wrote:

i think what you want is:

Code:

<when green flag clicked>
<forever>
<if><key[ up ] keypressed>
<point in direction( 0 
<end>
<if><key[ left ] key pressed>
<point in direction( -90
<end>

so on

Close, but it should be [turn cw (2) degrees] for up;
[turn ccw (2) degrees] for down.
If you just point in one direction for each, then that limits it to two directions.


"I'd love to change the world, but they haven't released the source code yet."
Check out the latest version of Streak --> http://billy.scienceontheweb.net/Streak

Offline

 

#11 2009-07-19 15:49:54

dusski
Scratcher
Registered: 2009-06-04
Posts: 75

Re: direction moving towards how to

The-Whiz wrote:

Ok this is getting complicated...

Code:

/^^^^^^^^^^^^^^^\_____
[When flag clicked____]
[forever]
[][if <key [right arrow] pressed?>]
[][][turn [5] degrees right]
[][end of if______________________]
[][if <key [left arrow] pressed?>]
[][][turn [5] degrees left]
[][end of if_____________________]
[][if <key [up arrow] pressed?>]
[][][move [5] steps]
[][end of if___________________]
[][if <(direction) > (45)>]
[][][point in direction (45)]
[][end of if_____________________]
[][if <(direction) < (-45)>]
[][][point in direction (-45)]
[][end of if_____________________]
[][if <key [up arrow] pressed?]
[][][change (Y-vel) by 1]
[][else]
[][][change (Y-vel) by -1]
[][end of if_________________]
[][change y by (Y-vel)]
[end of forever]

this last doesn't work with Y-vel. Do you have some other idea?


dusski

Offline

 

#12 2009-07-19 15:54:18

The-Whiz
Scratcher
Registered: 2007-07-09
Posts: 1000+

Re: direction moving towards how to

Well do you mean


Code:

/^^^^^^^^^^^^^^^\_____
[When flag clicked____]
[forever]
[][if <key [right arrow] pressed?>]
[][][turn [5] degrees right]
[][end of if______________________]
[][if <key [left arrow] pressed?>]
[][][turn [5] degrees left]
[][end of if_____________________]
[][if <key [up arrow] pressed?>]
[][][move [5] steps]
[][else]
[][][move [-5] steps]
[][end of if___________________]
[][if <(direction) > (45)>]
[][][point in direction (45)]
[][end of if_____________________]
[][if <(direction) < (-45)>]
[][][point in direction (-45)]
[][end of if_____________________]
[end of forever]

I don't really understand what you mean...

Offline

 

#13 2009-07-19 21:01:57

dusski
Scratcher
Registered: 2009-06-04
Posts: 75

Re: direction moving towards how to

The-Whiz wrote:

[][if <key [up arrow] pressed?]
[][][change (Y-vel) by 1]
[][else]
[][][change (Y-vel) by -1]
[][end of if_________________]
[][change y by (Y-vel)]
[end of forever]

This part dont work well. Dont you have another idea on this principle?


dusski

Offline

 

#14 2009-07-29 09:21:13

dusski
Scratcher
Registered: 2009-06-04
Posts: 75

Re: direction moving towards how to

i want to make something like this:
when i press space to fire i want my laser to go there * my pointer was when i pressed space


dusski

Offline

 

#15 2009-07-29 10:38:19

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: direction moving towards how to

do you mean?:

Code:

Sprite1:

<when green flag clicked>
<forever>
<if><mouse down?>
<go to x:( <mouse x> )y:( <mouse y>)
<end>
<end>

Sprite2 (This one is the laser)

<when green flag clicked>
<forever>
<wait until><mouse down?>
<play sound[ Laser sound ]
<repeat until><< <touching[ Enemy] <or> <touching[ edge] >>
<point in direction( Sprite1)
<move( 10 )steps>
<end>
<end>

Is that what your wanting?


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#16 2009-07-29 17:13:37

dusski
Scratcher
Registered: 2009-06-04
Posts: 75

Re: direction moving towards how to

markyparky56 wrote:

do you mean?:

Code:

Sprite1:

<when green flag clicked>
<forever>
<if><mouse down?>
<go to x:( <mouse x> )y:( <mouse y>)
<end>
<end>

Sprite2 (This one is the laser)

<when green flag clicked>
<forever>
<wait until><mouse down?>
<play sound[ Laser sound ]
<repeat until><< <touching[ Enemy] <or> <touching[ edge] >>
<point in direction( Sprite1)
<move( 10 )steps>
<end>
<end>

Is that what your wanting?

no it isn't working do you have something else on your mind


dusski

Offline

 

#17 2009-07-30 06:17:16

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: direction moving towards how to

what isn't working about it?


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#18 2009-07-30 06:20:51

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: direction moving towards how to

You may need to add in a <go to[ player


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#19 2009-11-26 22:05:06

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: direction moving towards how to

If you want to use Y-vel, you have to use trig. You have to change the Y-vel by the cosine of the direction, and use a variable X-vel, changed by the sine of the direction. Lastly, you must change the X and Y by X-vel and Y-vel, respectively. You would get something like this (I added a resetting script at the beginning and used 1/10 values):
[blocks]
<when green flag clicked>
<set{ X-vel }to( 0
<set{ Y-vel }to( 0
<go to x sad  0 )y sad  0
<forever>
<if><key[ right arrow ]pressed?>
<turn cw( 5 )degrees>
<end>
<if><key[ left arrow ]pressed?>
<turn ccw( 5 )degrees>
<end>
<if><( <direction> <<> -45 )>
<point in direction( -45
<end>
<if><( <direction> <>> 45 )>
<point in direction( 45
<end>
<if><key[ up arrow ]pressed?>
<change{ X-vel }by( sin(<direction>)
<change{ Y-vel }by( cos(<direction>)
<else>
<change{ Y-vel }by( -1
<end>
<change x by( (( <{ X-vel }> <*> 0.1 ))
<change y by( (( <{ Y-vel }> <*> 0.1 ))
<end>
[/blocks]


nXIII

Offline

 

Board footer