Jump to content

nested if statements


MadMax50

Recommended Posts

hello,

I am trying to get a nested if statement to work properly in sops.

First I have my constraints being deleted by the Y value

then if the Y value is less than a certain value , I want to set @strength=-1 based on a random condition. 

Then i want to delete all the constraints that are not @strength=-1

The result should just be  only the constraints that are @strength=-1  if it is below a certain @P.y value. 

I am not sure what I am doing wrong here...

float myRand= rand(@primnum*234.234);

f@strength=100;

if(@P.y<chf("Thresh_Y")){
    if(myRand>chf("Thresh")){
        f@strength=-1;
            if(f@strength>0){
                removeprim(0,@primnum,0);
        }
   }
   
}

 

I will also attach my scene file for anyone that wants to take a look

Thank you. 

nested_if_statements.hipnc

Link to comment
Share on other sites

If I understood you correctly this is what you want, I put color instead of deleting so you can see what is happening. Add the removeprim function where @Cd is or put a blast at the end "@strength==-1" and check delete non selected.

 

float myRand= rand(@primnum*234.234);

f@strength=100;

if(@P.y<chf("Thresh_Y")){
    f@strength=-1;
    @Cd = {1,0,0};
    } else if (myRand>chf("Thresh")) {    
        f@strength=-1;
        @Cd = {0,1,0};
}

 

 

 

 

Link to comment
Share on other sites

@SepuThank you. I am trying to keep f@strength=-1 and delete everything else when it gets below a certain Y value. 

Basically i am trying to achieve an rbd sim that breaks below a certain Y value but some pieces stay together.  

I'll attach my scene with the simple rbd sim to show you what I mean.

I implemented your method into it but I am not sure how I will achieve this without another if statement in there. 

Thank you.

nested_rbd.hipnc

Link to comment
Share on other sites

this: float myRand= rand(@primnum*234.234);

is generating your random number based on @primnum, but since you are deleting constraints it will change each time so it will not be stable

create prim attrib on constraints before the sim, like: i@primid = @primnum;

then in your code use: float myRand= rand(i@primid*234.234);

Link to comment
Share on other sites

you are updating positions of your constraints, I get that it's cause you want to detect the P.y, but you can't leave them like that

the constraint have to stay at rest, so just use it to create your attributes for deleting, then transfer those to original constraints and delete

depending on what you are doing you may be able to use clustering instead of having to alter stuff in DOPs, but I guess this is just a proof of concept for more complex behaviors

nested_rbd2_fix.hipnc

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...