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

#1 2010-09-24 00:44:05

MSobyak1
New Scratcher
Registered: 2010-09-24
Posts: 4

Making an action when releasing a key.. question

Hi,
I want to basically make something so when you hold a key down then release it, upon release it sends an action. More specifically.. to "shoot" an object across the room... If you ever played Half Life 2, I'm trying to recreate the gravity gun. I have the script already to pick things up, however, I also need to figure out how to have it only pick 1 item up at a time. But essencially I want to hold space down to hold the item with the gun, then when you release space it shoots the object in the direction the player is facing.

Any ideas? I've tried a bunch of things but nothing seems to be working. I want to stick to 1 key for hold and release... i've had it working with 2 keys but I like just 1. Thanks!

Offline

 

#2 2010-09-24 00:48:45

Jonathanpb
Scratcher
Registered: 2008-07-25
Posts: 1000+

Re: Making an action when releasing a key.. question

Would something like this work?

[when green flag clicked)
[forever]
[][wait until <key [space] pressed?>]
[][action for picking up the item goes here]
[][wait until <not <key [space] pressed?>>]
[][action for releasing the item goes here]
[end forever]

Last edited by Jonathanpb (2010-09-24 00:49:06)


"Human beings... must have action; and they will make it if they cannot find it.
-Charlotte Brontë

Offline

 

#3 2010-09-24 01:15:18

MSobyak1
New Scratcher
Registered: 2010-09-24
Posts: 4

Re: Making an action when releasing a key.. question

the wait until's cause the object to not move for some reason.. leme put what i have

http://i46.photobucket.com/albums/f101/msobyak1/scripts.jpg

the script on the left is my attempt at 1 key function. the script on the right is 2 keys. The Wait Until makes the object the gun is picking up not move at all no matter where I put it. I tried an <If not key pressed > with in the <if key pressed> but it doesn't recognise the statement.

Offline

 

#4 2010-09-24 04:47:35

MSobyak1
New Scratcher
Registered: 2010-09-24
Posts: 4

Re: Making an action when releasing a key.. question

ok i think i have it working, could use velocity to make it more smooth like I had it in the other version. But here is what I have now:

http://i46.photobucket.com/albums/f101/msobyak1/scripts2.jpg

Now the question is: How do I get to only effect 1 object up at a time? Meaning not only do i not want it to pick 2 objects up, but I dont even want it to pull 2 objects at the same time.

Offline

 

#5 2010-09-24 06:59:49

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: Making an action when releasing a key.. question

The best option I could think of would be to have the gravity gun sprite determine which pick-upable object is closest, then only pick that one up.


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#6 2010-09-24 07:27:17

MSobyak1
New Scratcher
Registered: 2010-09-24
Posts: 4

Re: Making an action when releasing a key.. question

yeah i was thinking that, just wonder what would happen if 2 objects were the same distance if it would get confussed. Is there a way to put colission on the objects as well? so they cant share the same exact x/y posission? this is a prototype for taking it into a 3d program so I'm tryin to think ahead as well. If there are 100 items you can pick up, would get pretty taxing to do distances between every object.

Offline

 

#7 2010-09-24 19:21:19

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: Making an action when releasing a key.. question

Oh, there's a lot of objects? That could make it difficult. I suppose you could have the items store their positions in lists, and somehow order them (maybe my x position) to make it easier to manage all the data.


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

Board footer