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

#1 2012-05-08 12:48:03

SD7
Scratcher
Registered: 2011-09-15
Posts: 100+

Fluid Movement Code

I'm working on making movement code for the "AI" (not really intelligent, but whatever) with this other guy, but the code we have set up feels really mechanical and stiff. We had to modify it from the glide code in order to add a pause function to the game. Does anyone know any good movement code to add to the enemies that feels like they're not on a fixed movement pattern, but will also respond to the variable "pause" being active and immediately stop moving?
Thanks for any input.

This is the game (without pause and glide code):
http://scratch.mit.edu/projects/SD7/2492155

This is our WIP version that has the mechanical-feeling movement that we're trying to fix:
http://scratch.mit.edu/projects/SD7/2522396


http://img834.imageshack.us/img834/4411/signaturespacegame2.png

Offline

 

#2 2012-05-09 00:15:49

SD7
Scratcher
Registered: 2011-09-15
Posts: 100+

Re: Fluid Movement Code

So... no one?


http://img834.imageshack.us/img834/4411/signaturespacegame2.png

Offline

 

#3 2012-05-09 00:33:58

jji7skyline
Scratcher
Registered: 2010-03-08
Posts: 1000+

Re: Fluid Movement Code

Well, try making it move with a (velocity) variable.

But TBH the jerky movement looks pretty nice  tongue


I don't know why you say goodbye, I say hello!  big_smile

Offline

 

#4 2012-05-09 00:38:29

SD7
Scratcher
Registered: 2011-09-15
Posts: 100+

Re: Fluid Movement Code

Would that change the mechanical look, and make it move more smoothly? Right now they move along a pattern more like this, and I'd rather they follow a pattern more like this.


http://img834.imageshack.us/img834/4411/signaturespacegame2.png

Offline

 

#5 2012-05-09 01:53:46

jji7skyline
Scratcher
Registered: 2010-03-08
Posts: 1000+

Re: Fluid Movement Code

Ah, I see, you'd have to use velocity variables, like this.

when gf clicked
forever
 move (velocity) steps
end
when gf clicked
repeat [10]
 change [velocity v] by [1]
end
repeat [10]
 change [velocity v] by [-1]
end
Try that script in a new project and see if that's the kind of movement you want.

Last edited by jji7skyline (2012-05-09 01:55:14)


I don't know why you say goodbye, I say hello!  big_smile

Offline

 

#6 2012-05-09 11:24:41

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Fluid Movement Code

SD7, did you not post a similar question a few days ago? If it's the same project, I posted a possible solution on the other thread.  smile

Offline

 

#7 2012-05-10 11:37:51

SD7
Scratcher
Registered: 2011-09-15
Posts: 100+

Re: Fluid Movement Code

@jji7skyline: I tried that and the ship stays at the top of the screen and doesn't move. Not sure if I'm setting the code up right, haven't messed with velocity before.
http://img545.imageshack.us/img545/3624 … city01.png
It plays the [change velocity by 1] code for about 1 second, and then that code shuts off (it's not highlighted in the side anymore

@LS97: This is all you said

LS97 wrote:

To avoid this, you can make your own glide method that mimics the block, but also checks for the pause variable every so often.

You never explained how to do that

Last edited by SD7 (2012-05-10 12:16:05)


http://img834.imageshack.us/img834/4411/signaturespacegame2.png

Offline

 

#8 2012-05-11 11:55:20

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Fluid Movement Code

OK then, I'll explain.

Constructing the whole script for you would take some time, so I'll just point you in the right direction. Try using something like this:

forever
  . . . // do stuff
  set [x change v] to [10]  // replace glide method
  set [y change v] to [10]
  repeat (10)
    change x by ((x change) / (10))
    change y by ((y change) / (10))
    wait until <(paused) = (false)>
  end
end
Of course, that won't work very well and it has no control over time, but you can see where I'm getting  wink

Last edited by LS97 (2012-05-11 11:56:08)

Offline

 

#9 2012-05-11 14:03:12

SD7
Scratcher
Registered: 2011-09-15
Posts: 100+

Re: Fluid Movement Code

Ok, that makes sense, but what's supposed to be where "do stuff" is? What else does it need to do?

Last edited by SD7 (2012-05-11 14:03:26)


http://img834.imageshack.us/img834/4411/signaturespacegame2.png

Offline

 

#10 2012-05-11 14:05:48

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Fluid Movement Code

SD7 wrote:

Ok, that makes sense, but what's supposed to be where "do stuff" is? What else does it need to do?

Oh, that's just representing any script that needs to come before the glide.
I just assumed that is how you structured your code, but you can also simply replace the single "glide for X seconds" block with all the scripts that come after the ".../do stuff"

Offline

 

#11 2012-05-12 20:21:18

itsmomito
Scratcher
Registered: 2008-03-28
Posts: 100+

Re: Fluid Movement Code

Hmmm... Velocity is a good idea. I'll post a script here for Space Game when i'm done with it.

Offline

 

Board footer