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

#1 2012-03-14 10:09:01

mrbacak
New Scratcher
Registered: 2012-03-14
Posts: 2

Movement + throw (javelin game ??)

hi

im trying to create something in scratch where by the user can move the sprite (javelin thrower) forwards and backwards and then release a javelin which is attached to the thrower when a key is pressed.

The javelin needs to go in an arc & fall to the ground  , once the user has thrown the javelin the game should reset.

Any help or guidance would be thanked

Offline

 

#2 2012-03-14 10:14:12

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Movement + throw (javelin game ??)

I know it has something to do with trig, but I'm sure what.  tongue

Offline

 

#3 2012-03-14 10:17:45

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Movement + throw (javelin game ??)

Well, you need a javelin sprite, and it needs to use the following script:

when gf clicked
forever
repeat until <key [space v] pressed?>// follow mouse till space pressed
go to [mouse-pointer v]
end
wait (0.1) secs
set [xvel v] to ((mouse x) - (x position))
set [yvel v] to ((mouse y) - (y position))
repeat until <touching [edge v]?>
change x by (xvel)
change y by (yvel)
change [yvel v] by (-1)
end
wait (5) secs


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#4 2012-03-14 10:31:54

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Re: Movement + throw (javelin game ??)

Hardmath123 wrote:

Well, you need a javelin sprite, and it needs to use the following script:

when gf clicked
forever
repeat until <key [space v] pressed?>// follow mouse till space pressed
go to [mouse-pointer v]
end
wait (0.1) secs
set [xvel v] to ((mouse x) - (x position))
set [yvel v] to ((mouse y) - (y position))
repeat until <touching [edge v]?>
change x by (xvel)
change y by (yvel)
change [yvel v] by (-1)
end
wait (5) secs

You need direction as well.
I think it's this:

if <(y position) > [0]>
 point in direction ([atan v] of (([0] - (x velocity)) / ([0] - (y velocity))))
else
 point in direction ([0] - ([atan v] of (([0] - (x velocity)) / ([0] - (y velocity)))))

Offline

 

#5 2012-03-14 10:34:17

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Movement + throw (javelin game ??)

Splodgey wrote:

Hardmath123 wrote:

Well, you need a javelin sprite, and it needs to use the following script:

when gf clicked
forever
repeat until <key [space v] pressed?>// follow mouse till space pressed
go to [mouse-pointer v]
end
wait (0.1) secs
set [xvel v] to ((mouse x) - (x position))
set [yvel v] to ((mouse y) - (y position))
repeat until <touching [edge v]?>
change x by (xvel)
change y by (yvel)
change [yvel v] by (-1)
end
wait (5) secs

You need direction as well.
I think it's this:

if <(y position) > [0]>
 point in direction ([atan v] of (([0] - (x velocity)) / ([0] - (y velocity))))
else
 point in direction ([0] - ([atan v] of (([0] - (x velocity)) / ([0] - (y velocity)))))
end

Oh, yeah. Thanks for that!


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#6 2012-03-15 07:45:53

mrbacak
New Scratcher
Registered: 2012-03-14
Posts: 2

Re: Movement + throw (javelin game ??)

thanks hardmath but i need to know how to tie the javelin to the thrower and move the thrower forwards & backwards + when space is pressed realease


can you help me with this ??

Offline

 

#7 2012-03-15 12:08:07

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Re: Movement + throw (javelin game ??)

mrbacak wrote:

thanks hardmath but i need to know how to tie the javelin to the thrower and move the thrower forwards & backwards + when space is pressed realease


can you help me with this ??

You can use this;

repeat until <key [space v] pressed?>
goto [Player v]
end
I've just realised; what do you mean?
if that doesn't work (It's slightly in the wrong place or something)
repeat until <key [space v] pressed?>
set x to (([x position v] of [player v]) + (How much it's in the wrong place)) //or -
set y to (([y position v] of [player v]) + (How much it's in the wrong place)) //again, or -
end

Offline

 

Board footer