Change Radius On Collision

About advanced scenes, and the Thyme scripting language used in Algodoo.

Change Radius On Collision

Postby haircutbob » Thu May 02, 2013 4:45 am

I'm sure this is a very easy fix, but I can't find it anywhere, so I made an account and am now making this post! Haha. I want to change the radius of a spawned circle when it collides with a stationary box. I'm sure I would use e.other.blank = blank, but every code I try fails. Is there some other way I can accomplish this, or can someone give me the correct variable and format to plug in? Thanks.
haircutbob
 
Posts: 8
Joined: Thu May 02, 2013 4:35 am

Re: Change Radius On Collision

Postby jon_joy_1999 » Thu May 02, 2013 9:38 am

does the circle change it's own size when it hits the stationary box, or does the box change the size of the circle when the box is hit by it?
Image
BSrac = BoincStats recent average credit
I'd rather be network computing.
jon_joy_1999
 
Posts: 233
Joined: Fri Dec 09, 2011 12:51 am

Re: Change Radius On Collision

Postby haircutbob » Fri May 03, 2013 4:21 am

Hmm, I guess it doesn't really matter, as long as the radius isn't changed until it hits this specific box. Just know that it will be colliding with other geometries before it hits this one.
haircutbob
 
Posts: 8
Joined: Thu May 02, 2013 4:35 am

Re: Change Radius On Collision

Postby Xray » Sat May 04, 2013 6:22 pm

haircutbob wrote:Hmm, I guess it doesn't really matter, as long as the radius isn't changed until it hits this specific box. Just know that it will be colliding with other geometries before it hits this one.


In the OnCollide script for the circle, simply add: radius = n (n = any floating point number > zero). For example, the resulting code
will look like this: OnCollide = (e)=>{radius = 3.14}


If you want the colliding geometry to change the radius of the circle, you then would use:
OnCollide = (e)=>{e.other.radius = 3.14}

Just make sure that the collision layer of the colliding geometries are the same. For example, if the circle collision layer is "A" (number 1 in script menu), then the collision layer of the colliding geometry must also be "A".
User avatar
Xray
 
Posts: 501
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Change Radius On Collision

Postby haircutbob » Sat May 04, 2013 6:33 pm

e.other.radius = n was the first thing I tried. It didn't work. Have you tested this for yourself? Are you sure it works for you. And changing it within the circle won't work because
1. It is a circle that is spawned on laser hit, and as far as I know you can't change oncollide for spawned objects
2. It will be colliding with many other parts before it hits this.
haircutbob
 
Posts: 8
Joined: Thu May 02, 2013 4:35 am

Re: Change Radius On Collision

Postby Xray » Sat May 04, 2013 6:49 pm

haircutbob wrote:e.other.radius = n was the first thing I tried. It didn't work. Have you tested this for yourself? Are you sure it works for you. And changing it within the circle won't work because
1. It is a circle that is spawned on laser hit, and as far as I know you can't change oncollide for spawned objects
2. It will be colliding with many other parts before it hits this.


Yes, I tried it and it works (refer to the uploaded sample scene).

You can add script to a spawned geometry either BEFORE it gets spawned, or AFTER it gets spawned. If you cannot do either than you are doing something wrong.

In the sample scene, the ball collides with the square on the left, which changes the ball's radius, but the ball passes by the square on the right because the collision layers are different.

Hope this helps.
Attachments
Test scene for haircutbob.phz
Sample scene for haircutbob.
(5.43 KiB) Downloaded 26 times
User avatar
Xray
 
Posts: 501
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Change Radius On Collision

Postby haircutbob » Sun May 05, 2013 5:43 am

Oh wow. Terrible news. The radius didn't change in the sample scene. So how do you add script before? When I press enter after inputing the code, the program always crashes. It just didn't think it supported multiple layers of code.
haircutbob
 
Posts: 8
Joined: Thu May 02, 2013 4:35 am

Re: Change Radius On Collision

Postby Xray » Sun May 05, 2013 6:28 am

haircutbob wrote:Oh wow. Terrible news. The radius didn't change in the sample scene.


Your program must be bad for some reason. I would suggest uninstalling the program, then download the latest version and install it. After doing that, if you still have trouble, then there may be something going on with your computer.

haircutbob wrote:So how do you add script before? When I press enter after inputing the code, the program always crashes. It just didn't think it supported multiple layers of code.


You add whatever code you want to the OnCollide script box, or any of the other user configurable script boxes within the script that defines the geometry that you want to spawn. Then when the geometry actually spawns, it will include the user script that you added to the script that defines the geometry to be spawned. After the geometry is spawned, it is just like any other geometry. That is, you should be able to enter new script, or alter existing script.

Tip: In the code that defines a geometry to be spawned, DO NOT include "GeomID" or "body". If either or both are written in the code, then delete them. The reason is, if more than one geometry gets spawned with the same id number, then they will act like they are glued to each other. Algodoo will think that all of the spawned geometries that have the same id number are ONE geometry! If you spawn geometries without those id numbers, then Algodoo will automatically assign sequential numbers to newly spawned objects.
User avatar
Xray
 
Posts: 501
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Change Radius On Collision

Postby electronicboy » Sun May 05, 2013 5:10 pm

@Haircutbob;
What version of algodoo are you using?
Please make sure you are using one of the more recent versions of algodoo, preferiblty 2.1.0 if your PC can support it.
I'm not sure but writing to .radius, if I remember correctly, has only been added in the 2.* branch of algodoo somewhere along the line, but I can't locate what version it is!

@Xray;
EntityID is also another variable to avoid spawning, This can cause problems with adding hinges or fixates, as both use EntityID as to locate the object they're connected too!
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: Change Radius On Collision

Postby haircutbob » Sun May 05, 2013 5:48 pm

Well crap. I knew I was about to be told to update. Haha. I'm just hesitant to because I don't know if all my engines will still run. Have the physics been changed much in the new Algodoo? I found another way to accomplish what I want with less scripting, but if the newer version isn't very different as far as physics go, I might just bite the bullet and update. Thanks a lot for the help and patients so far by the way. It's much appreciated.
haircutbob
 
Posts: 8
Joined: Thu May 02, 2013 4:35 am

Re: Change Radius On Collision

Postby electronicboy » Sun May 05, 2013 11:23 pm

To be fair, I suggest just go ahead with it and try the update!
Most older scenes do run fine except in a few cases.

When installing algodoo, backup your my documents/Algodoo folder, tell algodoo to not uninstall the new version, and install the Algodoo program files into a new directory instead of the default!

If you decide you want to go back, just restore the backup (Mainly the configuration file), and uninstall the new version, and reset file associations (You'll be asked what you want to do with .phz files when you click on them. Just select Program Files (x86 on x64 Windows installs)/Algodoo/Algodoo.exe.

Good luck!
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: Change Radius On Collision

Postby haircutbob » Mon May 06, 2013 2:46 am

Thanks, yeah I was considering doing that anyway. Though I might not now because I accomplished what I wanted pretty perfectly. I wanted to show you guys but don't know how to upload an attachment.
haircutbob
 
Posts: 8
Joined: Thu May 02, 2013 4:35 am

Re: Change Radius On Collision

Postby electronicboy » Mon May 06, 2013 12:39 pm

Upload the file to algobox, when uploaded, on the scene description page is a text box on the left with

Code: Select all
[scene]xxxxxx[/scene]

And paste that code into a reply!

Or, click 'post reply' on the forums to open the advanced editor and use the upload tab.

Glad you've sorted out your issue!
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: Change Radius On Collision

Postby haircutbob » Tue May 07, 2013 3:00 am

Rating: rated 5.5
Filesize: 89.45 kB
Comments: 5
Ratings: 2
download


Thanks!
haircutbob
 
Posts: 8
Joined: Thu May 02, 2013 4:35 am

Re: Change Radius On Collision

Postby electronicboy » Tue May 07, 2013 3:58 am

Looks like a nice scene from what I can see, It just won't run in 2.1.0! :(
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: Change Radius On Collision

Postby haircutbob » Tue May 07, 2013 4:40 am

Nooooooo! I was afraid of that. Looks like I have work to do. Thanks again for all your help.
haircutbob
 
Posts: 8
Joined: Thu May 02, 2013 4:35 am


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 4 guests