Browse Search Popular Register Upload Rules User list Login:
Search:
For Enz0

Image:
screenshot of the scene

Author: Xray

Group: Default

Filesize: 5.54 kB

Date added: 2021-11-28

Rating: 5

Downloads: 927

Views: 372

Comments: 29

Ratings: 1

Times favored: 0

Made with: Algodoo v2.1.0

Tags:

Scene tag

Here's how it works:

1. The collision layer of the gun (it is collision layer A) should be different from the projectiles (bullets). Here the collision layer for bullets is B (in the script menu, layer B is shown as 2).

2. The laser does not need to be directly in line with bullet trajectory. I moved it at an angle so that the laser won't interfere with the bullets in any way. (e.pos is the x/y position where the laser beam hits the square). The bullets shoot straight away from e.pos because I made the velocity [50,0] which means they will shoot straight out from e.pos (in the positive X direction) at a fast velocity. I made the Y value zero so that the bullets will shoot parallel to the ground, rather than at a positive or negative slope.

3. I made the Ctrl key a trigger. You can poke it quickly for a single shot, or hold it down and the gun will be a machine gun.

4. Notice that there are MANY parameters that you can change in order to make the bullets look and act differently (color, velocity, size, and many other things) than they currently do. Play around with those parameters so that you understand what they do and how it makes the bullets interact with other geometries in the scene.

Oh, one more thing I forgot to mention: It's good practice to make the ground plane a "killer" and have the same collision layer as the bullets. If the bullets don't get deleted, they will pile up and eventually there will be so many that it will cause slow computers to LAG. You can either let that ground plane kill them, or in the script that generates the circles you can make each one have a timeToLive of some short time period like maybe 1 second, or maybe 0.1 second (whatever works for your particular scene).

Have fun!
Last edited at 2021/11/28 21:04:48 by Xray
Please log in to rate this scene
edit
This scene is a response to:
Title Author Rating Downloads Comments Date added
0 ( votes)
show grid
Thank you Xray!
You're welcome Enz0!
Btw can i use this?
Actually nevermind.
Hey Xray! I was wondering, but can you detect whether an object is "touching something else? And if so, can you detect whether a condition about the other object is true, and if so, do something? I was trying to make a scene that relies on physics and stuff to conduct electricity, like touching a battery would power a bulb on.
JP - Yes to all. Take a look at my scene: Electronic Circuit


I see that you have a lot of questions concerning Thyme Scripting, so I suggest that you check out the heading "Thyme Scripting" in the Algodoo Forum. There's a lot of good information there but you will have to put in the time and effort that's required to do the research.
Last edited at 2021/12/05 17:41:04 by Xray
Like, the "OnCollide" event but holds the whole way through like "onLaserHit"
when you put a script in a custom variable or controlleracc, do you need to call for it to work or is it always on like poststep?
We used to use controlleracc like postStep because postStep was added at some later date after Algodoo first came out. You will see that in many of the older scenes in the Algobox archive (probably before 2012 or thereabout).

Concerning custom (also known as Local) variables, it depends if you used them like a called subroutine, or like a function which you can pass data to. If you use a local variable as a called subroutine, then just show the name of the variable in your postStep script. For example if you create a subroutine that does some calculation and you named it _sub, you can call it in postStep like the following:

temp >= 17 ? {_sub}:{}

Read the first couple of posts in the "Thyme Scripting" heading in the Algodoo FORUM for information the explains how variables and functions are created and used. There's a lot of good information there. Way too much to explain here in comments.
I did and I awnsered my own question, but I have a new one, is there a way to make a "For" loop in scripting? Or in other words, with scripts can I make a loop that repeats a specified ammount of times, for example, a bomb that when it collides with something, it repeats and action 3 times and explodes.
Yes, there are at least two different FOR loop functions that users have employed in their scenes over the years. 1. Algodoo (or more accurately, Thyme) has an intrinsic FOR loop function which works just fine for repeating a block of code N times, where N is limited to some relatively small value (I don't recall what that value is). 2. User kilinich developed a much better FOR loop which he called "Xfor", and that's the one that many of us experienced Thyme coders typically use. Below is the script which needs to be entered into the Console only once when a scene is loading and spawning objects. Here is the actual code for it:

scene.my.xFor := (n1, n2, code) =>
{n2 > n1 ? {
m := (n1 + n2) / 2;
scene.my.xFor(n1, m, code);
scene.my.xFor(m + 1, n2, code)
} : {code(n1)}
}

I don't recall the details of how to use it, but there are plenty of posts in the Thyme Scripting portion of the Algodoo forum that discuss using it in great detail. The beauty of this function is the fact that the number of iterations is only limited by the amount of memory your computer has! (in other words, it is limited by a VERY big number!)
Hi Xray, I have a scene that need 2 combine 2 individual variables into a list, I tried doing something like: _list = [_x, _y] but it messed up the scene. Is there some special way you need to do it?
I don't know why that would mess up your scene because it looks correct. You are creating an array named "_list" which contains two elements "_x" and "_y". Maybe you did something else that messed it up. Or maybe you tried to create that array BEFORE you created the two custom variables _x and _y. That could be what caused your problem. Can you go ahead and post your scene? You can title it "For Xray". In the scene description explain what you did just before it messed up, and explain what you would like it to do. Maybe I can figure out why it got messed up. Do you want to do that?
Sorry, I fixed it, instead of using the distance formula I used the array on the tracer size. I probably should have double checked it. Sorry about that.
No problem! If you learned from this experience then it was a success! :tup:
Hi Xray, I have more questions, are they getting annoying? I could try and look in forums first if you want.

I've tried copy and pasting a spring that's on an object and adding to to an oncollide script, it doesn't add the spring, it just does nothing, how does scene.addspring work?

Also, is it possible to change the surfaces in a polygon?
Last edited at 2022/01/26 22:16:12 by ezpz(fib)5
ezpz(fib)5 -- Sorry, I never used scene.addspring, and so I'm not sure how it works or how the spring endpoints attach to certain objects. You will have to research that one.

Concerning changing the surfaces in a polygon, yes it can be done but it's rather complicated if you are asking what I think you are asking. Are you asking about changing the SHAPE of a polygon, or are you asking about changing the texture to a different one? I want to confirm exactly what you are asking before I try to explain it.
I am asking about changing the shape of the polygon, I want to make a thing that drills holes into it.
That will be difficult and complicated to do. Also, it will operate very slowly. Here is an example of a scene that user kilinich made a long time ago that melts ice. You can change the ice to wood or metal and the scene will still work. Play with it and see if this is something you can use: MELT ICE
Oh, thanks, the scene is pretty much what I was trying to do.
Hi Xray, sorry for bothering if I am, I have another question. How can you do app.gui.showmessage but instead of just in the centre you can choose the positions they go to?
ezpz(fib)5 -- Sorry, I never have used that function in any of my scenes. I looked for information about it in the Algodoo Forum but could not find much of anything there about it. If I recall, user s_noonan has used that in one or more of his scenes, and so I suggest that you ask him about it. You could comment him on one of his latest scenes.
Hi Xray, do you know any way to split a number into a list of digits, for example 210 would be [2,1,0]?
_temp1 = _temp0 % 10;
_temp0 = _temp0 - _temp1;
_temp0 = _temp0 / 10;
_temp2 = _temp0 % 10;
_temp0 = _temp0 - _temp2;
_temp0 = _temp0 / 10;
_temp3 = _temp0 % 10;
_array = [_temp3, _temp2, _temp1]

The initial value "210" is in _temp0. After you run this script the three digits will be placed in the array as [2,1,0]. You probably know this, but you must define those local variables before you can use them. You can do that in "onSpawn". for example:
_temp0 = 210 (or whatever number you need to split)
_temp1 = 0;
_temp2 = 0;
_temp3 = 0;
_array = []


I'm sure the code would run faster and would be more compact if you did a FOR loop instead of that list of linear steps, but I'll let you figure that out if you want to.
Last edited at 2022/05/26 05:52:52 by Xray
ok, thank you so much
do I need to make more temps for higher amount of digits?
Yes, if you use the same technique that I used here. The script can be made much simpler and easier to use if you wanted to spend the time to do that.
Xray, when you divide a number, like 10/3 how do you prevent rounding?
Make sure to include a decimal point. For example, if you enter 10/3 then Thyme will assume you are diving integers which will result in an integer answer. If you enter 10.0/3.0 it will give the answer as a real number: 3.3333