Random movement of some little objects?
Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller
-
- Posts: 26
- Joined: Mon Nov 16, 2020 8:16 pm
Random movement of some little objects?
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.
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.
-
- Livecode Opensource Backer
- Posts: 5393
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Random movement of some little objects?
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.
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.
-
- Livecode Opensource Backer
- Posts: 5393
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Random movement of some little objects?
Have fun, stay safe, and have a very Happy Christmas.

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.
-
- 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?
Hi.
Try this.
Change the value in the ordinary field to change the move rate.
Craig
Try this.
Change the value in the ordinary field to change the move rate.
Craig
Re: Random movement of some little objects?
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).
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.
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.

-
- Posts: 26
- Joined: Mon Nov 16, 2020 8:16 pm
Re: Random movement of some little objects?
Thank you very much for your help
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.

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.
Re: Random movement of some little objects?
I should have made a better distinction in the terms, and for that I apologize Francesco77.Francesco77 wrote: ↑Wed Dec 23, 2020 6:12 pmI 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.
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 -
As to the wisdom in it's use, I suppose that would depend on the user.

-
- 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?
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
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
Re: Random movement of some little objects?
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.



-
- Livecode Opensource Backer
- Posts: 5393
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Random movement of some little objects?
OK, OK: time for a flame throwing contest . . .
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.
- -
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).

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.
- -
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
-
- Posts: 26
- Joined: Mon Nov 16, 2020 8:16 pm
Re: Random movement of some little objects?
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
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.
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

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.
-
- Livecode Opensource Backer
- Posts: 5393
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Random movement of some little objects?
I made a similar sort of thing in Director in 1998 . . . both
a long time ago
no code Ding-An-Sich whatsoever.
a long time ago
no code Ding-An-Sich whatsoever.
Re: Random movement of some little objects?
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
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
-
- 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?
You can simply create a list of random points, of any length, and not have to scribble.
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
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
Craig
-
- Posts: 26
- Joined: Mon Nov 16, 2020 8:16 pm
Re: Random movement of some little objects?
I tried the following this morning:
1. I put the points of a curve I made into a variable:
2. I set the position of the movable object to the first point of the curve (outside the visible part of the stack)
3. I called a handler "FlyOfTheBumblebee" which moves the bee to the next point of the curve and calls itself at last:
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
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?
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
Code: Select all
set the loc of image "bee01_rechts" to line 1 in l_pointsCurve_01
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
...
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

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?