Random movement of some little objects?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Francesco77
Posts: 26
Joined: Mon Nov 16, 2020 8:16 pm

Random movement of some little objects?

Post by Francesco77 » Tue Dec 22, 2020 8:27 pm

I am creating a little game for kids.

To make the different scenes a little bit more lively I would like to add little objects (like dandelions and bees) that fly or float around.
I need about 15 dandelion seeds and 3 to 5 bees that fly around randomly to achieve this effect.

What is the best way to tell the sprites how to move? Can this be done without slowing down the whole game?

Since I am not a great mathematician or physicist I wonder, if code or scripts exist already that I can buy or use or learn from for my project.

Thanks in advance for your help.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5393
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Random movement of some little objects?

Post by richmond62 » Tue Dec 22, 2020 8:44 pm

Neither code nor sprites exist.

However, the important thing is that you can move things around, and if
you use without waiting they should neither interfere with each other or slow things down.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5393
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Random movement of some little objects?

Post by richmond62 » Tue Dec 22, 2020 8:59 pm

Screenshot 2020-12-22 at 21.57.39.png
-
Have fun, stay safe, and have a very Happy Christmas. 8)

I removed my stack as a newer version is available lower down.
Last edited by richmond62 on Thu Dec 24, 2020 11:10 am, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7407
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Random movement of some little objects?

Post by dunbarx » Wed Dec 23, 2020 12:17 pm

Hi.

Try this.
randomMover.livecode.zip
(2.81 KiB) Downloaded 32 times
Change the value in the ordinary field to change the move rate.

Craig

bogs
Posts: 5104
Joined: Sat Feb 25, 2017 10:45 pm

Re: Random movement of some little objects?

Post by bogs » Wed Dec 23, 2020 2:00 pm

As a completely different suggestion, you could also try the old 'revanimation' library. I'm not entirely sure why they took it out of the IDE after 2.2.x, however, it was still in the IDE folders (/.runrev/components/livecodecommunity-7.1.4 (x86_64)/Toolset/Unsupported/revanimation.rev) as of 7.1.4 and can be used from the plugins folder of the current IDE with no issues (tested in 9.6.x).
aPic_aLittleAnimated.png
Getting animated the incredibly easy way...
If you decide to try this route and don't know how to use it, I'll be happy to throw up a video for you to look at, but it really is pretty dead simple.
Image

Francesco77
Posts: 26
Joined: Mon Nov 16, 2020 8:16 pm

Re: Random movement of some little objects?

Post by Francesco77 » Wed Dec 23, 2020 6:12 pm

Thank you very much for your help :D

Especially dunbarx' example gave me some ideas how to achieve what I want to do.

I did not know that the move command can be used to move an object to the vertex points of a graphical line to one point after the other.
That movement looks quite smooth when setting the right time for the movement.

I also had a look at the revanimation library which looks like a useful tool for creating animations.
Since it is no longer part of the official LiveCode IDE I am not sure if it is wise to use it. As a beginner I am afraid that this could be a source of problems that I cannot estimate.

I think I will follow dunbarx' approach.

I will try to find a way to create random paths so that the objects move other ways each time the game starts.
For that it seems that I have to revive a little bit of my long forgotten knowledge of geometry from my school days.

In the next step I will change the speed of the movement randomly so that the movement looks a bit more natural.

bogs
Posts: 5104
Joined: Sat Feb 25, 2017 10:45 pm

Re: Random movement of some little objects?

Post by bogs » Wed Dec 23, 2020 9:06 pm

Francesco77 wrote:
Wed Dec 23, 2020 6:12 pm
I also had a look at the revanimation library which looks like a useful tool for creating animations.
Since it is no longer part of the official LiveCode IDE I am not sure if it is wise to use it.
I should have made a better distinction in the terms, and for that I apologize Francesco77.

The animation builder is no longer part of the IDE (although, as I said, it is easily re-instated), the animation library on the other hand is certainly still part of the IDE, as you can see from this entry in the dictionary -
aPic_AnimatedLibrary.png
Would you like a book?
As to the wisdom in it's use, I suppose that would depend on the user.
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7407
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Random movement of some little objects?

Post by dunbarx » Wed Dec 23, 2020 10:41 pm

Hi.

You can see that I simply scribbled four curve graphics and then hid them. If you take the time, you can draw much more complex shapes. Be aware that you can make one, duplicate it, and then rotate or flip it, thus creating a total of eight new graphics from just one.

Craig

bogs
Posts: 5104
Joined: Sat Feb 25, 2017 10:45 pm

Re: Random movement of some little objects?

Post by bogs » Wed Dec 23, 2020 11:53 pm

I decided to record a (very) small and (extremely) simple use of the animation builder, just in case you decide to look into it later. I did not use any of the more advanced parts of it, such as setting acceleration / deceleration or really anything other than keyframe rigging. Hopefully it will be of some use to anyone else stumbling along on this thread.

Image
Image

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5393
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Random movement of some little objects?

Post by richmond62 » Thu Dec 24, 2020 11:08 am

OK, OK: time for a flame throwing contest . . . 8)

Seriously . . . not really.

However Mr "I'd rather use a spade than a mechanical digger" has been faffing around with 'flowers',
randomised moveSpeed and without waiting
and come to some slightly odd conclusions.

TRIGGER WARNING

To fully understand what is written next you will have to download my stack and run it several times.
-
Screenshot 2020-12-24 at 12.00.11.png
-
This stack features 12 moving objects which should be able to move across the full width of the stack (1000 pixels) and
the full height of the stack (700 pixels). Movement runs through 30 iterations.

NOW, from about iteration 5 to about iteration 25 (as far as my subjective senses can work out) all the images appear
to cluster much nearer to the centre of the stack (which, as far as I can tell means that without waiting has limitations).
Attachments
BUZZ.livecode.zip
Here's the stack.
(68.77 KiB) Downloaded 24 times

Francesco77
Posts: 26
Joined: Mon Nov 16, 2020 8:16 pm

Re: Random movement of some little objects?

Post by Francesco77 » Thu Dec 24, 2020 1:29 pm

Thank you so much for your help!

I will have a look at the BUZZ file tomorrow since my family and my grandchild will kill me if I spend the christmas evening at my computer :wink:

I have made a little movie of a movement solution I made in Adobe Director years ago.
Maybe this is better than explaining what I want to achieve with words only.

Unfortunately I did only use the random movement behaviours or scripts and did not write them myself.
They are quite complex with bezier curves and a lot of other things I never really understood.
Nevertheless they worked very well as you can see in the little movie I made.

Sorry for the bad quality and the wrong resolution. This is my very first movie that I uploaded to YT.
I hope it will work though.

https://youtu.be/zN3UkDwm2WU


I wish everyone happy holidays and a peaceful Christmas.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5393
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Random movement of some little objects?

Post by richmond62 » Thu Dec 24, 2020 1:37 pm

I made a similar sort of thing in Director in 1998 . . . both

a long time ago

no code Ding-An-Sich whatsoever.

Xero
Posts: 89
Joined: Sat Jun 23, 2018 2:22 pm

Re: Random movement of some little objects?

Post by Xero » Sat Dec 26, 2020 5:26 am

I am sure if you're using objects running across smooth curves, you can randomise the points of the curve using the random() function, and that way the curve itself will create random shapes for the objects to run across.
I'd need to play with it to see how easy and fast that is to do.

Select random x value of point 1, select random y value of point 1, set point 1 as these values
Do this in a repeat loop for the number of points of the curve
Do this in a repeat loop for the number of curves
Move objects along curve as a path.

XdM

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7407
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Random movement of some little objects?

Post by dunbarx » Sat Dec 26, 2020 4:11 pm

You can simply create a list of random points, of any length, and not have to scribble.

Code: Select all

on mouseUp
   repeat 1000
      put random(500) & "," & random(500) & return after scribblelessPointList
   end repeat
   
   repeat with y = 1 to 1000
      move btn 2 from line y of scribblelessPointList to line(y+1) of scribblelessPointList in 20
   end repeat
end mouseUp
But if you have such a list, or a very "large" scribble, why would you need to change any part of it? Nobody will notice, if you repeat the journey, that is has already been travelled.

Craig

Francesco77
Posts: 26
Joined: Mon Nov 16, 2020 8:16 pm

Re: Random movement of some little objects?

Post by Francesco77 » Wed Dec 30, 2020 11:54 am

I tried the following this morning:

1. I put the points of a curve I made into a variable:

Code: Select all

put the points of graphic "Curve_01" into l_pointsCurve_01
2. I set the position of the movable object to the first point of the curve (outside the visible part of the stack)

Code: Select all

 set the loc of  image "bee01_rechts" to line 1 in l_pointsCurve_01
3. I called a handler "FlyOfTheBumblebee" which moves the bee to the next point of the curve and calls itself at last:

Code: Select all

 
...
 if l_currline < number of lines in l_pointsCurve_01 then
      add 1 to l_currLine
   else
      exit FlyOfTheBumblebee
   end if 
       move image "bee01_rechts" to line l_currLine in l_pointsCurve_01 in 0.1 without waiting
      send FlyOfTheBumblebee to me in 10 milliseconds
      ...
      
This works and makes the movement controllable to a certain extent.

I found two problems:

1. The movement is not really smooth. Instead it seems to be a little jerky at some points.

2. It seems to me that the "points" of a graphic describe only the necessary waypoints of the curves. Parts of the graphical line which are straight lines are described bei two points only regardless the distance.
This leads to a behaviour in which the moving objects jumps to the next point instead of following the graphical line point by point.
In my case the moved bees switch on the turbo and move a lot faster along every straight part of the graphical line.
That looks quite funny but unfortunately not very natural :wink:

Is there a way to move an object strictly along every single point of a graphical line?
Or is there maybe a another way to move the objects I have not yet thought of?

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”